done RecipeDefaultManager

pull/55/head
Alexandre AGOSTINHO 2 years ago
parent 3bcca963e6
commit 17e8b0f648

@ -85,7 +85,7 @@ steps:
- name: docker-image-console-app - name: docker-image-console-app
image: plugins/docker image: plugins/docker
settings: settings:
dockerfile: MCTG/Dockerfile dockerfile: MCTG/ConsoleApp/Dockerfile
context: MCTG/ context: MCTG/
registry: hub.codefirst.iut.uca.fr registry: hub.codefirst.iut.uca.fr
repo: hub.codefirst.iut.uca.fr/alexandre.agostinho/console-mctg repo: hub.codefirst.iut.uca.fr/alexandre.agostinho/console-mctg

@ -3,7 +3,11 @@
"path": "SAE-2.01.sln", "path": "SAE-2.01.sln",
"projects": [ "projects": [
"ConsoleApp\\ConsoleApp.csproj", "ConsoleApp\\ConsoleApp.csproj",
"Exception\\AppException.csproj",
"Managers\\Managers.csproj",
"Model\\Model.csproj", "Model\\Model.csproj",
"Persistance\\DataPersistence\\DataPersistence.csproj",
"Persistance\\FakePersistance\\FakePersistance.csproj",
"Tests\\Model_UnitTests\\Model_UnitTests.csproj" "Tests\\Model_UnitTests\\Model_UnitTests.csproj"
] ]
} }

@ -1,5 +1,7 @@
using AppException; using AppException;
using Model; using Model;
using System.Reflection;
using System.Runtime.CompilerServices;
namespace Managers namespace Managers
{ {
@ -63,18 +65,40 @@ namespace Managers
return recipe; return recipe;
} }
public RecipeCollection GetRecipesByPriorityOrder(Priority priority) public RecipeCollection GetRecipesByPriorityOrder(IEnumerable<Priority> priorities)
{ {
IEnumerable<Recipe> recipes = from Recipe recipe in _dataManager.GetFromData<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 where recipe.Priority == priority
select recipe; select recipe;
recipes.AddRange(recipesWithCurrentPriority);
}
return new RecipeCollection( return new RecipeCollection(
$"Suggestions", recipes.ToArray()); $"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;
} }
} }
} }

@ -12,8 +12,8 @@ namespace Model
Recipe GetRecipeFromId(int id); Recipe GetRecipeFromId(int id);
RecipeCollection GetRecipeByTitle(string title); RecipeCollection GetRecipeByTitle(string title);
RecipeCollection GetRecipeByAuthor(string authorMail); RecipeCollection GetRecipeByAuthor(string authorMail);
RecipeCollection GetRecipesByPriorityOrder(Priority priority); RecipeCollection GetRecipesByPriorityOrder(IEnumerable<Priority> priority);
bool AddRecipeToData(Recipe recipe); bool AddRecipeToData(Recipe recipe);
bool ModifyRecipeInData(Recipe recipe); bool ModifyRecipeInData(Recipe oldRecipe, Recipe newRecipe);
} }
} }

@ -8,7 +8,7 @@ namespace Model_UnitTests
public void TestVoidConstructor() public void TestVoidConstructor()
{ {
Recipe r = new Recipe( Recipe r = new Recipe(
title: "test recipe", type: RecipeType.Unspecified); title: "test recipe", type: RecipeType.Unspecified, priority: Priority.Easy);
Assert.NotNull(r.Title); Assert.NotNull(r.Title);
} }

Loading…
Cancel
Save