From d658bea8023075b686f388bb7dc2489aeb3a5a4b Mon Sep 17 00:00:00 2001 From: Yannis Date: Sat, 10 Apr 2021 00:25:08 +0300 Subject: [PATCH 1/7] -Filled RecipeAddDTO -Started Update Recipes --- CRUDRecipeEF.BL/DTOs/RecipeAddDTO.cs | 10 ++++- CRUDRecipeEF.BL/Services/IRecipeService.cs | 2 + CRUDRecipeEF.BL/Services/RecipeService.cs | 10 +++++ CRUDRecipeEF.PL/Menus/RecipeMenu.cs | 45 ++++++++++++++++++++-- 4 files changed, 63 insertions(+), 4 deletions(-) diff --git a/CRUDRecipeEF.BL/DTOs/RecipeAddDTO.cs b/CRUDRecipeEF.BL/DTOs/RecipeAddDTO.cs index 356d722..d167ec0 100644 --- a/CRUDRecipeEF.BL/DTOs/RecipeAddDTO.cs +++ b/CRUDRecipeEF.BL/DTOs/RecipeAddDTO.cs @@ -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 Recipes { get; set; } = new(); } } \ No newline at end of file diff --git a/CRUDRecipeEF.BL/Services/IRecipeService.cs b/CRUDRecipeEF.BL/Services/IRecipeService.cs index f290617..3867bd9 100644 --- a/CRUDRecipeEF.BL/Services/IRecipeService.cs +++ b/CRUDRecipeEF.BL/Services/IRecipeService.cs @@ -1,6 +1,7 @@ using System.Collections.Generic; using System.Threading.Tasks; using CRUDRecipeEF.BL.DTOs; +using CRUDRecipeEF.DAL.Entities; namespace CRUDRecipeEF.BL.Services { @@ -18,5 +19,6 @@ public interface IRecipeService Task RemoveIngredientFromRecipe(string ingredientName, string recipeName); Task DeleteRecipe(string name); + Task UpdateRecipe(Recipe recipe, string newName); } } \ No newline at end of file diff --git a/CRUDRecipeEF.BL/Services/RecipeService.cs b/CRUDRecipeEF.BL/Services/RecipeService.cs index d0abb2a..512bcda 100644 --- a/CRUDRecipeEF.BL/Services/RecipeService.cs +++ b/CRUDRecipeEF.BL/Services/RecipeService.cs @@ -75,6 +75,16 @@ public async Task AddRecipe(RecipeDTO recipeAddDTO) return recipeAddDTO.Name; } + public async Task UpdateRecipe (Recipe recipe, string newName) + { + await GetRecipeByNameIfExists(recipe.Name); + + var a = new Recipe(); + a.Ingredients = recipe.Ingredients; + + await DeleteRecipe(recipe.Name); + } + /// /// /// diff --git a/CRUDRecipeEF.PL/Menus/RecipeMenu.cs b/CRUDRecipeEF.PL/Menus/RecipeMenu.cs index 5571c40..506f90a 100644 --- a/CRUDRecipeEF.PL/Menus/RecipeMenu.cs +++ b/CRUDRecipeEF.PL/Menus/RecipeMenu.cs @@ -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 { @@ -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, @@ -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; @@ -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; @@ -93,6 +104,34 @@ private async Task ExecuteMenuSelection(RecipeMenuOption option) } } + private async void UpdateRecipe() + { + ConsoleHelper.ColorWrite("What recipe would you like to update: "); + var name = Console.ReadLine(); + + ConsoleHelper.ColorWrite("What is the new name of the recipe: "); + Console.WriteLine(); + var newName = Console.ReadLine(); + + var recipe = new Recipe() {Name = name }; + + await _recipeService.UpdateRecipe(recipe, newName); + + + + //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(); @@ -145,7 +184,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 From e5b9d3afd39de1d116b21f5cec4278568b3a8fdc Mon Sep 17 00:00:00 2001 From: Yannis Date: Sun, 11 Apr 2021 11:18:29 +0300 Subject: [PATCH 2/7] a --- CRUDRecipeEF.BL/Services/RecipeService.cs | 10 +++++----- CRUDRecipeEF.PL/Menus/RecipeMenu.cs | 9 +++------ 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/CRUDRecipeEF.BL/Services/RecipeService.cs b/CRUDRecipeEF.BL/Services/RecipeService.cs index 512bcda..3b5f068 100644 --- a/CRUDRecipeEF.BL/Services/RecipeService.cs +++ b/CRUDRecipeEF.BL/Services/RecipeService.cs @@ -75,14 +75,12 @@ public async Task AddRecipe(RecipeDTO recipeAddDTO) return recipeAddDTO.Name; } - public async Task UpdateRecipe (Recipe recipe, string newName) + public async Task UpdateRecipe (RecipeDTO recipeDTO, string newName) { - await GetRecipeByNameIfExists(recipe.Name); + var recipe = await GetRecipeByNameIfExists(newName); - var a = new Recipe(); - a.Ingredients = recipe.Ingredients; + _mapper.Map(recipeDTO, recipe); - await DeleteRecipe(recipe.Name); } /// @@ -183,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.PL/Menus/RecipeMenu.cs b/CRUDRecipeEF.PL/Menus/RecipeMenu.cs index 506f90a..4d17fe8 100644 --- a/CRUDRecipeEF.PL/Menus/RecipeMenu.cs +++ b/CRUDRecipeEF.PL/Menus/RecipeMenu.cs @@ -107,16 +107,13 @@ private async Task ExecuteMenuSelection(RecipeMenuOption option) private async void UpdateRecipe() { ConsoleHelper.ColorWrite("What recipe would you like to update: "); - var name = Console.ReadLine(); + var recipe = Console.ReadLine(); ConsoleHelper.ColorWrite("What is the new name of the recipe: "); Console.WriteLine(); - var newName = Console.ReadLine(); - - var recipe = new Recipe() {Name = name }; - - await _recipeService.UpdateRecipe(recipe, newName); + var newRecipeName = Console.ReadLine(); + var a = new RecipeDTO(); //var checkedRecipeDTO = new RecipeUpdateDTO { Name = name }; From 6c50a9296ec3c1755adc3b38050570449b14315b Mon Sep 17 00:00:00 2001 From: Yannis Date: Sun, 11 Apr 2021 13:54:54 +0300 Subject: [PATCH 3/7] - --- CRUDRecipeEF.BL/Services/IRecipeService.cs | 2 +- CRUDRecipeEF.BL/Services/RecipeService.cs | 7 +++---- CRUDRecipeEF.PL/Menus/RecipeMenu.cs | 6 ++++-- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/CRUDRecipeEF.BL/Services/IRecipeService.cs b/CRUDRecipeEF.BL/Services/IRecipeService.cs index 3867bd9..0fb52b7 100644 --- a/CRUDRecipeEF.BL/Services/IRecipeService.cs +++ b/CRUDRecipeEF.BL/Services/IRecipeService.cs @@ -19,6 +19,6 @@ public interface IRecipeService Task RemoveIngredientFromRecipe(string ingredientName, string recipeName); Task DeleteRecipe(string name); - Task UpdateRecipe(Recipe recipe, string newName); + Task UpdateRecipe(RecipeDTO recipe, string newName); } } \ No newline at end of file diff --git a/CRUDRecipeEF.BL/Services/RecipeService.cs b/CRUDRecipeEF.BL/Services/RecipeService.cs index 3b5f068..e78b3b7 100644 --- a/CRUDRecipeEF.BL/Services/RecipeService.cs +++ b/CRUDRecipeEF.BL/Services/RecipeService.cs @@ -75,12 +75,11 @@ public async Task AddRecipe(RecipeDTO recipeAddDTO) return recipeAddDTO.Name; } - public async Task UpdateRecipe (RecipeDTO recipeDTO, string newName) + public async Task UpdateRecipe (RecipeDTO recipe, string newName) { - var recipe = await GetRecipeByNameIfExists(newName); - - _mapper.Map(recipeDTO, recipe); + recipe.Name = newName; + await Save(); } /// diff --git a/CRUDRecipeEF.PL/Menus/RecipeMenu.cs b/CRUDRecipeEF.PL/Menus/RecipeMenu.cs index 4d17fe8..cb096c3 100644 --- a/CRUDRecipeEF.PL/Menus/RecipeMenu.cs +++ b/CRUDRecipeEF.PL/Menus/RecipeMenu.cs @@ -107,13 +107,15 @@ private async Task ExecuteMenuSelection(RecipeMenuOption option) private async void UpdateRecipe() { ConsoleHelper.ColorWrite("What recipe would you like to update: "); - var recipe = Console.ReadLine(); + 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(); - var a = new RecipeDTO(); + await _recipeService.UpdateRecipe(recipe, newRecipeName); //var checkedRecipeDTO = new RecipeUpdateDTO { Name = name }; From 550881cd48cc520fce1368bf8cf06a0aa8b54c0d Mon Sep 17 00:00:00 2001 From: Yannis Date: Sun, 11 Apr 2021 22:19:15 +0300 Subject: [PATCH 4/7] -Completed Class RecipeAddDTO -Completed Ingredient Name Edit --- CRUDRecipeEF.BL/Services/IRecipeService.cs | 2 +- CRUDRecipeEF.BL/Services/RecipeService.cs | 7 +++++-- CRUDRecipeEF.PL/Menus/RecipeMenu.cs | 17 ++--------------- 3 files changed, 8 insertions(+), 18 deletions(-) diff --git a/CRUDRecipeEF.BL/Services/IRecipeService.cs b/CRUDRecipeEF.BL/Services/IRecipeService.cs index 0fb52b7..3a16d7e 100644 --- a/CRUDRecipeEF.BL/Services/IRecipeService.cs +++ b/CRUDRecipeEF.BL/Services/IRecipeService.cs @@ -19,6 +19,6 @@ public interface IRecipeService Task RemoveIngredientFromRecipe(string ingredientName, string recipeName); Task DeleteRecipe(string name); - Task UpdateRecipe(RecipeDTO recipe, string newName); + 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 e78b3b7..2adbd60 100644 --- a/CRUDRecipeEF.BL/Services/RecipeService.cs +++ b/CRUDRecipeEF.BL/Services/RecipeService.cs @@ -75,9 +75,12 @@ public async Task AddRecipe(RecipeDTO recipeAddDTO) return recipeAddDTO.Name; } - public async Task UpdateRecipe (RecipeDTO recipe, string newName) + public async Task UpdateRecipe (RecipeDTO recipeDTO, string recipeName) { - recipe.Name = newName; + var recipe = await GetRecipeByNameIfExists(recipeDTO.Name); + + recipe.Name = recipeName; + _mapper.Map(recipeDTO); await Save(); } diff --git a/CRUDRecipeEF.PL/Menus/RecipeMenu.cs b/CRUDRecipeEF.PL/Menus/RecipeMenu.cs index cb096c3..bec1156 100644 --- a/CRUDRecipeEF.PL/Menus/RecipeMenu.cs +++ b/CRUDRecipeEF.PL/Menus/RecipeMenu.cs @@ -113,22 +113,9 @@ private async void UpdateRecipe() ConsoleHelper.ColorWrite("What is the new name of the recipe: "); Console.WriteLine(); - var newRecipeName = Console.ReadLine(); + var recipeName = 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); + await _recipeService.UpdateRecipe(recipe, recipeName); } private async Task ListRecipe() From 5f9fa6d40066ef7e48aa1b45347ba7076ca3a111 Mon Sep 17 00:00:00 2001 From: Yannis Date: Sun, 11 Apr 2021 22:37:05 +0300 Subject: [PATCH 5/7] Repaired IRecipeService --- CRUDRecipeEF.BL/Services/IRecipeService.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/CRUDRecipeEF.BL/Services/IRecipeService.cs b/CRUDRecipeEF.BL/Services/IRecipeService.cs index 3a16d7e..b1e9746 100644 --- a/CRUDRecipeEF.BL/Services/IRecipeService.cs +++ b/CRUDRecipeEF.BL/Services/IRecipeService.cs @@ -1,6 +1,7 @@ using System.Collections.Generic; using System.Threading.Tasks; using CRUDRecipeEF.BL.DTOs; +using CRUDRecipeEF.DAL.DTOs; using CRUDRecipeEF.DAL.Entities; namespace CRUDRecipeEF.BL.Services From 8c3d857866151372a43e997a7d5988ffbe7b7a87 Mon Sep 17 00:00:00 2001 From: Yannis Date: Sun, 11 Apr 2021 22:47:59 +0300 Subject: [PATCH 6/7] Done it --- CRUDRecipeEF.BL/Services/RecipeService.cs | 1 - CRUDRecipeEF.DAL/DTOs/MenuAddDTO.cs | 3 ++- CRUDRecipeEF.DAL/DTOs/RecipeAddDTO.cs | 3 ++- CRUDRecipeEF.DAL/DTOs/RecipeCategoryAddDTO.cs | 3 ++- CRUDRecipeEF.PL/Menus/RecipeMenu.cs | 2 -- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/CRUDRecipeEF.BL/Services/RecipeService.cs b/CRUDRecipeEF.BL/Services/RecipeService.cs index 636e0df..b561723 100644 --- a/CRUDRecipeEF.BL/Services/RecipeService.cs +++ b/CRUDRecipeEF.BL/Services/RecipeService.cs @@ -78,7 +78,6 @@ public async Task AddRecipe(RecipeDTO recipeAddDTO) public async Task UpdateRecipe (RecipeDTO recipeDTO, string recipeName) { var recipe = await GetRecipeByNameIfExists(recipeDTO.Name); - recipe.Name = recipeName; _mapper.Map(recipeDTO); 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 d167ec0..e6ad554 100644 --- a/CRUDRecipeEF.DAL/DTOs/RecipeAddDTO.cs +++ b/CRUDRecipeEF.DAL/DTOs/RecipeAddDTO.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using CRUDRecipeEF.DAL.DTOs; +using System.Collections.Generic; using System.ComponentModel.DataAnnotations; namespace CRUDRecipeEF.BL.DTOs 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 495b9f5..f796a36 100644 --- a/CRUDRecipeEF.PL/Menus/RecipeMenu.cs +++ b/CRUDRecipeEF.PL/Menus/RecipeMenu.cs @@ -5,8 +5,6 @@ using CRUDRecipeEF.BL.Services; using CRUDRecipeEF.DAL.DTOs; using Microsoft.Extensions.Logging; -using CRUDRecipeEF.BL.Helpers; -using CRUDRecipeEF.DAL.Entities; namespace CRUDRecipeEF.PL.Menus { From 15801b9044a3931fb709d1b79c641af334f3976c Mon Sep 17 00:00:00 2001 From: Yannis Date: Wed, 14 Apr 2021 19:50:06 +0300 Subject: [PATCH 7/7] delete mapper --- CRUDRecipeEF.BL/Services/RecipeService.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/CRUDRecipeEF.BL/Services/RecipeService.cs b/CRUDRecipeEF.BL/Services/RecipeService.cs index b561723..43b2d8a 100644 --- a/CRUDRecipeEF.BL/Services/RecipeService.cs +++ b/CRUDRecipeEF.BL/Services/RecipeService.cs @@ -79,7 +79,6 @@ public async Task UpdateRecipe (RecipeDTO recipeDTO, string recipeName) { var recipe = await GetRecipeByNameIfExists(recipeDTO.Name); recipe.Name = recipeName; - _mapper.Map(recipeDTO); await Save(); }