|
|
|
@ -1,6 +1,7 @@
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Security.Cryptography.X509Certificates;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
@ -8,12 +9,12 @@ using Model;
|
|
|
|
|
|
|
|
|
|
namespace ConsoleApp
|
|
|
|
|
{
|
|
|
|
|
internal class SearcherRecipe
|
|
|
|
|
internal class SearcherRecipe : IMenuDisplay
|
|
|
|
|
{
|
|
|
|
|
public int CurrentLine
|
|
|
|
|
{
|
|
|
|
|
get => _currentLine;
|
|
|
|
|
set
|
|
|
|
|
private set
|
|
|
|
|
{
|
|
|
|
|
_currentLine = value;
|
|
|
|
|
if (_currentLine > _maxLines)
|
|
|
|
@ -28,28 +29,48 @@ namespace ConsoleApp
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public RecipeCollection SearchResult { get; private set; }
|
|
|
|
|
|
|
|
|
|
public Recipe? CurrentSelected { get; private set; }
|
|
|
|
|
public string ResearchStr { get; set; }
|
|
|
|
|
|
|
|
|
|
private RecipeCollection _allRecipes;
|
|
|
|
|
private string _researchStr = "";
|
|
|
|
|
private int _currentLine = 0;
|
|
|
|
|
private int _maxLines = 0;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void UpdateDisplay(string researchStr, RecipeCollection researchResult)
|
|
|
|
|
|
|
|
|
|
public SearcherRecipe(RecipeCollection recipes)
|
|
|
|
|
{
|
|
|
|
|
_allRecipes = recipes;
|
|
|
|
|
SearchResult = recipes;
|
|
|
|
|
ResearchStr = "";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool ComputeSearch(string researchStr = "")
|
|
|
|
|
{
|
|
|
|
|
_maxLines = researchResult.Count - 1;
|
|
|
|
|
ResearchStr = researchStr;
|
|
|
|
|
SearchResult = _allRecipes.ResearchByName(ResearchStr.ToLower());
|
|
|
|
|
_maxLines = SearchResult.Count - 1;
|
|
|
|
|
|
|
|
|
|
return SearchResult.Count > 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void UpdateDisplay()
|
|
|
|
|
{
|
|
|
|
|
StringBuilder sb = new StringBuilder();
|
|
|
|
|
sb.AppendLine("---------------------------------------------------------");
|
|
|
|
|
sb.AppendLine($" Research: {researchStr}");
|
|
|
|
|
sb.AppendLine($" Research: {ResearchStr}");
|
|
|
|
|
sb.AppendLine("---------------------------------------------------------");
|
|
|
|
|
for (int i = 0; i < researchResult.Count; i++)
|
|
|
|
|
for (int i = 0; i < SearchResult.Count; i++)
|
|
|
|
|
{
|
|
|
|
|
if (i == CurrentLine)
|
|
|
|
|
{
|
|
|
|
|
CurrentSelected = researchResult[i];
|
|
|
|
|
CurrentSelected = SearchResult[i];
|
|
|
|
|
sb.Append($">");
|
|
|
|
|
}
|
|
|
|
|
sb.AppendLine($" [ {researchResult[i].Id} ]: {researchResult[i].Title} ");
|
|
|
|
|
sb.AppendLine($" [ {SearchResult[i].Id} ]:\t{SearchResult[i].Title} ");
|
|
|
|
|
}
|
|
|
|
|
Console.Clear();
|
|
|
|
|
Console.WriteLine(sb);
|
|
|
|
|