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 7 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
3 changes: 3 additions & 0 deletions CRUDRecipeEF.BL/Services/IRecipeService.cs
Original file line number Diff line number Diff line change
@@ -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
{
Expand All @@ -18,5 +20,6 @@ public interface IRecipeService
Task RemoveIngredientFromRecipe(string ingredientName, string recipeName);

Task DeleteRecipe(string name);
Task UpdateRecipe(RecipeDTO recipeDTO, string recipeName);
}
}
11 changes: 11 additions & 0 deletions CRUDRecipeEF.BL/Services/RecipeService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,15 @@ public async Task<string> AddRecipe(RecipeDTO recipeAddDTO)
return recipeAddDTO.Name;
}

public async Task UpdateRecipe (RecipeDTO recipeDTO, string recipeName)
{
var recipe = await GetRecipeByNameIfExists(recipeDTO.Name);
recipe.Name = recipeName;
YannisAm marked this conversation as resolved.
Show resolved Hide resolved
_mapper.Map<RecipeDTO, Recipe>(recipeDTO);

await Save();
}

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


}
}
3 changes: 2 additions & 1 deletion CRUDRecipeEF.DAL/DTOs/MenuAddDTO.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using CRUDRecipeEF.BL.DTOs;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;

namespace CRUDRecipeEF.DAL.DTOs
Expand Down
11 changes: 10 additions & 1 deletion CRUDRecipeEF.DAL/DTOs/RecipeAddDTO.cs
Original file line number Diff line number Diff line change
@@ -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<IngredientDTO> Recipes { get; set; } = new();
}
}
3 changes: 2 additions & 1 deletion CRUDRecipeEF.DAL/DTOs/RecipeCategoryAddDTO.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using CRUDRecipeEF.BL.DTOs;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
Expand Down
29 changes: 26 additions & 3 deletions CRUDRecipeEF.PL/Menus/RecipeMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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();
Expand Down Expand Up @@ -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
Expand Down