|
|
|
@ -1,5 +1,7 @@
|
|
|
|
|
using AppException;
|
|
|
|
|
using Model;
|
|
|
|
|
using System.Reflection;
|
|
|
|
|
using System.Runtime.CompilerServices;
|
|
|
|
|
|
|
|
|
|
namespace Managers
|
|
|
|
|
{
|
|
|
|
@ -63,18 +65,40 @@ namespace Managers
|
|
|
|
|
return recipe;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public RecipeCollection GetRecipesByPriorityOrder(Priority priority)
|
|
|
|
|
public RecipeCollection GetRecipesByPriorityOrder(IEnumerable<Priority> priorities)
|
|
|
|
|
{
|
|
|
|
|
IEnumerable<Recipe> recipes = from Recipe recipe in _dataManager.GetFromData<Recipe>()
|
|
|
|
|
where recipe.Priority == priority
|
|
|
|
|
select recipe;
|
|
|
|
|
List<Recipe> recipes = new List<Recipe>();
|
|
|
|
|
IEnumerable<Recipe> recipesWithCurrentPriority;
|
|
|
|
|
foreach (Priority priority in priorities)
|
|
|
|
|
{
|
|
|
|
|
recipesWithCurrentPriority = from Recipe recipe in _dataManager.GetFromData<Recipe>()
|
|
|
|
|
where recipe.Priority == priority
|
|
|
|
|
select recipe;
|
|
|
|
|
recipes.AddRange(recipesWithCurrentPriority);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return new RecipeCollection(
|
|
|
|
|
$"Suggestions", recipes.ToArray());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool ModifyRecipeInData(Recipe recipe)
|
|
|
|
|
public bool ModifyRecipeInData(Recipe oldRecipe, Recipe newRecipe)
|
|
|
|
|
{
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
if (oldRecipe.Equals(newRecipe))
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
Recipe? recipe = _dataManager.GetFromData<Recipe>()
|
|
|
|
|
.ToList()
|
|
|
|
|
.Find(r => r.Equals(oldRecipe));
|
|
|
|
|
if (recipe is null)
|
|
|
|
|
throw new RecipeNotFoundException();
|
|
|
|
|
|
|
|
|
|
foreach (var property in typeof(Recipe).GetProperties()
|
|
|
|
|
.Where(prop => prop.CanWrite))
|
|
|
|
|
{
|
|
|
|
|
property.SetValue(oldRecipe, recipe);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|