Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature 25 edit options #101

Merged
merged 9 commits into from
Apr 16, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion CRUDRecipeEF.BL/DTOs/RecipeAddDTO.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
namespace CRUDRecipeEF.BL.DTOs
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;

namespace CRUDRecipeEF.BL.DTOs
{
public class RecipeAddDTO
{
public string Recipe { get; set; }
[StringLength(200, MinimumLength = 3)]
public string Name { get; set; }

public List<IngredientDTO> Recipes { get; set; } = new();
}
}
2 changes: 2 additions & 0 deletions CRUDRecipeEF.BL/Services/IRecipeService.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using CRUDRecipeEF.BL.DTOs;
using CRUDRecipeEF.DAL.Entities;

namespace CRUDRecipeEF.BL.Services
{
Expand All @@ -18,5 +19,6 @@ public interface IRecipeService
Task RemoveIngredientFromRecipe(string ingredientName, string recipeName);

Task DeleteRecipe(string name);
Task UpdateRecipe(RecipeDTO recipe, string newName);
YannisAm marked this conversation as resolved.
Show resolved Hide resolved
}
}
9 changes: 9 additions & 0 deletions CRUDRecipeEF.BL/Services/RecipeService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,13 @@ public async Task<string> AddRecipe(RecipeDTO recipeAddDTO)
return recipeAddDTO.Name;
}

public async Task UpdateRecipe (RecipeDTO recipe, string newName)
{
recipe.Name = newName;
YannisAm marked this conversation as resolved.
Show resolved Hide resolved

await Save();
}

/// <summary>
/// </summary>
/// <param name="name"></param>
Expand Down Expand Up @@ -173,5 +180,7 @@ private async Task<bool> RecipeExists(string recipeName)
{
return await _context.Recipes.AnyAsync(r => r.Name.ToLower() == recipeName.ToLower().Trim());
}


}
}
44 changes: 41 additions & 3 deletions CRUDRecipeEF.PL/Menus/RecipeMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using CRUDRecipeEF.BL.Helpers;
using CRUDRecipeEF.DAL.Entities;

namespace CRUDRecipeEF.PL.Menus
{
Expand All @@ -15,7 +17,11 @@ public class RecipeMenu : IRecipeMenu
private readonly ILogger _logger;
private readonly int _recipePerPage = 8;

private enum RecipeMenuOption { InValid = 0, NewRecipe = 1, LookUpRecipe = 2, ShowRecipe = 3, DeleteRecipe = 4, GoBack = 5 };
private enum RecipeMenuOption
{
InValid = 0, NewRecipe = 1, LookUpRecipe = 2, ShowRecipe = 3, DeleteRecipe = 4,
UpdateRecipe = 5, GoBack = 6
};

public RecipeMenu(IRecipeService recipeService,
IIngredientService ingredientService,
Expand All @@ -35,8 +41,9 @@ public async Task Show()
ConsoleHelper.ColorWriteLine("2.) Lookup Recipe");
ConsoleHelper.ColorWriteLine("3.) Show Recipe List");
ConsoleHelper.ColorWriteLine("4.) Delete Recipe");
ConsoleHelper.ColorWriteLine("5.) Update Recipe");
Console.WriteLine();
ConsoleHelper.ColorWriteLine(ConsoleColor.Red, "5.) Back to Main Menu");
ConsoleHelper.ColorWriteLine(ConsoleColor.Red, "6.) Back to Main Menu");
Console.WriteLine();

string input = string.Empty;
Expand Down Expand Up @@ -85,6 +92,10 @@ private async Task ExecuteMenuSelection(RecipeMenuOption option)
Console.WriteLine();
await DeleteRecipe();
break;
case RecipeMenuOption.UpdateRecipe:
Console.WriteLine();
UpdateRecipe();
break;
case RecipeMenuOption.GoBack:
Console.WriteLine();
break;
Expand All @@ -93,6 +104,33 @@ private async Task ExecuteMenuSelection(RecipeMenuOption option)
}
}

private async void UpdateRecipe()
{
ConsoleHelper.ColorWrite("What recipe would you like to update: ");
var input = Console.ReadLine();

var recipe = await _recipeService.GetRecipeByName(input);

ConsoleHelper.ColorWrite("What is the new name of the recipe: ");
Console.WriteLine();
var newRecipeName = Console.ReadLine();

await _recipeService.UpdateRecipe(recipe, newRecipeName);


//var checkedRecipeDTO = new RecipeUpdateDTO { Name = name };

//maybe add a try - catch

//var change =_recipeService.UpdateRecipe(newName, checkedRecipeDTO);

//_recipeService.DeleteRecipe(name);

//var newNameAddRecipeDTO = new RecipeAddDTO { Name = change };

//_recipeService.AddRecipe(newNameAddRecipeDTO);
}

private async Task ListRecipe()
{
Console.WriteLine();
Expand Down Expand Up @@ -145,7 +183,7 @@ private async Task NewRecipe()

while (another)
{
ConsoleHelper.ColorWrite("What ingredeient would you like to add: ");
ConsoleHelper.ColorWrite("What ingredient would you like to add: ");
var input = Console.ReadLine();

try
Expand Down