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.
54 lines
1.6 KiB
54 lines
1.6 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Security.Cryptography.X509Certificates;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using ConsoleApp.Menu.Core;
|
|
using Model;
|
|
using Model.Managers;
|
|
|
|
namespace ConsoleApp.Menu
|
|
{
|
|
/// <summary>
|
|
/// An utility to find a recipe.
|
|
/// </summary>
|
|
internal class SearcherRecipe : Menu<Recipe>
|
|
{
|
|
protected MasterManager _masterMgr;
|
|
protected RecipeCollection _recipeCollectionOnSearch = new RecipeCollection("search");
|
|
|
|
public SearcherRecipe(MasterManager masterManager) : base("Search recipe")
|
|
{
|
|
_masterMgr = masterManager;
|
|
}
|
|
|
|
#region Methods
|
|
protected List<Selector<Recipe>> ConvertRecipeCollectionInSelectors()
|
|
{
|
|
List<Selector<Recipe>> newSelectors = new List<Selector<Recipe>>();
|
|
foreach (Recipe recipe in _recipeCollectionOnSearch)
|
|
{
|
|
newSelectors.Add(new Selector<Recipe>(recipe, $"[{recipe.Id}]: {recipe.Title}"));
|
|
}
|
|
return newSelectors;
|
|
}
|
|
|
|
public override void Update()
|
|
{
|
|
_recipeCollectionOnSearch = _masterMgr.DataMgr.GetRecipes("all recipes");
|
|
_allSelectors = ConvertRecipeCollectionInSelectors();
|
|
base.Update();
|
|
}
|
|
|
|
public override IMenu? Return()
|
|
{
|
|
if (CurrentSelected == null)
|
|
return this;
|
|
|
|
return new PlainText(CurrentSelected.ToString());
|
|
}
|
|
#endregion
|
|
}
|
|
}
|