diff --git a/CRUDRecipeEF.BL/Services/IRecipeService.cs b/CRUDRecipeEF.BL/Services/IRecipeService.cs index d975de6..b1e9746 100644 --- a/CRUDRecipeEF.BL/Services/IRecipeService.cs +++ b/CRUDRecipeEF.BL/Services/IRecipeService.cs @@ -1,6 +1,8 @@ using System.Collections.Generic; using System.Threading.Tasks; +using CRUDRecipeEF.BL.DTOs; using CRUDRecipeEF.DAL.DTOs; +using CRUDRecipeEF.DAL.Entities; namespace CRUDRecipeEF.BL.Services { @@ -18,5 +20,6 @@ public interface IRecipeService Task RemoveIngredientFromRecipe(string ingredientName, string recipeName); Task DeleteRecipe(string name); + Task UpdateRecipe(RecipeDTO recipeDTO, string recipeName); } } \ No newline at end of file diff --git a/CRUDRecipeEF.BL/Services/RecipeService.cs b/CRUDRecipeEF.BL/Services/RecipeService.cs index 81b3d8d..43b2d8a 100644 --- a/CRUDRecipeEF.BL/Services/RecipeService.cs +++ b/CRUDRecipeEF.BL/Services/RecipeService.cs @@ -75,6 +75,14 @@ public async Task AddRecipe(RecipeDTO recipeAddDTO) return recipeAddDTO.Name; } + public async Task UpdateRecipe (RecipeDTO recipeDTO, string recipeName) + { + var recipe = await GetRecipeByNameIfExists(recipeDTO.Name); + recipe.Name = recipeName; + + await Save(); + } + /// /// /// @@ -173,5 +181,7 @@ private async Task RecipeExists(string recipeName) { return await _context.Recipes.AnyAsync(r => r.Name.ToLower() == recipeName.ToLower().Trim()); } + + } } \ No newline at end of file diff --git a/CRUDRecipeEF.DAL/DTOs/MenuAddDTO.cs b/CRUDRecipeEF.DAL/DTOs/MenuAddDTO.cs index 429d16e..cc5ffec 100644 --- a/CRUDRecipeEF.DAL/DTOs/MenuAddDTO.cs +++ b/CRUDRecipeEF.DAL/DTOs/MenuAddDTO.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using CRUDRecipeEF.BL.DTOs; +using System.Collections.Generic; using System.ComponentModel.DataAnnotations; namespace CRUDRecipeEF.DAL.DTOs diff --git a/CRUDRecipeEF.DAL/DTOs/RecipeAddDTO.cs b/CRUDRecipeEF.DAL/DTOs/RecipeAddDTO.cs index 1cf4d8c..e6ad554 100644 --- a/CRUDRecipeEF.DAL/DTOs/RecipeAddDTO.cs +++ b/CRUDRecipeEF.DAL/DTOs/RecipeAddDTO.cs @@ -1,6 +1,15 @@ -namespace CRUDRecipeEF.DAL.DTOs +using CRUDRecipeEF.DAL.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 Recipes { get; set; } = new(); } } \ No newline at end of file diff --git a/CRUDRecipeEF.DAL/DTOs/RecipeCategoryAddDTO.cs b/CRUDRecipeEF.DAL/DTOs/RecipeCategoryAddDTO.cs index e7741f7..96c2cf1 100644 --- a/CRUDRecipeEF.DAL/DTOs/RecipeCategoryAddDTO.cs +++ b/CRUDRecipeEF.DAL/DTOs/RecipeCategoryAddDTO.cs @@ -1,4 +1,5 @@ -using System; +using CRUDRecipeEF.BL.DTOs; +using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.Linq; diff --git a/CRUDRecipeEF.PL/Menus/RecipeMenu.cs b/CRUDRecipeEF.PL/Menus/RecipeMenu.cs index 3cc1eed..f796a36 100644 --- a/CRUDRecipeEF.PL/Menus/RecipeMenu.cs +++ b/CRUDRecipeEF.PL/Menus/RecipeMenu.cs @@ -15,7 +15,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, @@ -35,8 +39,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; @@ -85,6 +90,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; @@ -93,6 +102,20 @@ 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 recipeName = Console.ReadLine(); + + await _recipeService.UpdateRecipe(recipe, recipeName); + } + private async Task ListRecipe() { Console.WriteLine(); @@ -145,7 +168,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