You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
81 lines
2.7 KiB
81 lines
2.7 KiB
using AppException;
|
|
using Model;
|
|
|
|
namespace Managers
|
|
{
|
|
public class RecipeDefaultManager : IRecipeManager
|
|
{
|
|
private IDataManager _dataManager;
|
|
|
|
public RecipeDefaultManager(IDataManager dataManager)
|
|
{
|
|
_dataManager = dataManager;
|
|
}
|
|
|
|
public bool AddRecipeToData(Recipe recipe)
|
|
{
|
|
var recipeList = _dataManager.Data[nameof(Recipe)];
|
|
|
|
if (recipeList.Exists(r => r.Equals(recipe)))
|
|
return false;
|
|
|
|
_dataManager.Data[nameof(Recipe)].Add(recipe);
|
|
return true;
|
|
}
|
|
|
|
public RecipeCollection GetAllRecipes()
|
|
{
|
|
return new RecipeCollection(
|
|
"All recipes",
|
|
_dataManager.GetFromData<Recipe>().ToArray());
|
|
}
|
|
|
|
public RecipeCollection GetRecipeByAuthor(string authorMail)
|
|
{
|
|
User? author = _dataManager.GetFromData<User>()
|
|
.ToList()
|
|
.Find(u => u.Mail == authorMail);
|
|
if (author is null)
|
|
throw new UserNotFoundException(authorMail);
|
|
|
|
return new RecipeCollection(
|
|
$"{author.Name} {author.Surname}'s recipes",
|
|
_dataManager.GetFromData<Recipe>().ToArray());
|
|
}
|
|
|
|
public RecipeCollection GetRecipeByTitle(string title)
|
|
{
|
|
IEnumerable<Recipe> recipes = from Recipe recipe in _dataManager.GetFromData<Recipe>()
|
|
where recipe.Title.Contains(title)
|
|
select recipe;
|
|
return new RecipeCollection(
|
|
$"Search for '{title}'", recipes.ToArray());
|
|
}
|
|
|
|
public Recipe GetRecipeFromId(int id)
|
|
{
|
|
Recipe? recipe = _dataManager.GetFromData<Recipe>()
|
|
.ToList()
|
|
.Find(r => r.Id == id);
|
|
if (recipe is null)
|
|
throw new RecipeNotFoundException();
|
|
|
|
return recipe;
|
|
}
|
|
|
|
public RecipeCollection GetRecipesByPriorityOrder(Priority priority)
|
|
{
|
|
IEnumerable<Recipe> recipes = from Recipe recipe in _dataManager.GetFromData<Recipe>()
|
|
where recipe.Priority == priority
|
|
select recipe;
|
|
return new RecipeCollection(
|
|
$"Suggestions", recipes.ToArray());
|
|
}
|
|
|
|
public bool ModifyRecipeInData(Recipe recipe)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
}
|
|
}
|