import - export work! - fix get the recipes of the current user
continuous-integration/drone/push Build is passing Details

pull/48/head
Alexandre AGOSTINHO 2 years ago
parent 8580a6c1a4
commit 9a5d42c4a8

@ -6,6 +6,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DataPersistence;
namespace ConsoleApp.Menu
{
@ -22,10 +23,20 @@ namespace ConsoleApp.Menu
throw new ArgumentNullException();
Recipe recipe = CurrentSelected;
string path = $"export_{string.Concat(CurrentSelected.Title.Where(c => !char.IsWhiteSpace(c)))}";
// -- trying to put the right extention by checking the type of the DataManager...
//if (object.ReferenceEquals(_masterMgr.DataMgr.GetType(), typeof(DataContractXML)))
// path += ".xml";
//else if (object.ReferenceEquals(_masterMgr.DataMgr.GetType(), typeof(DataContractJSON)))
// path += ".json";
path += ".xml";
try
{
_masterMgr.DataMgr.Export(recipe, "");
_masterMgr.DataMgr.Export(recipe, path);
}
catch (ArgumentNullException e)
{

@ -16,12 +16,17 @@ namespace ConsoleApp.Menu
public override void Update()
{
_recipeCollectionOnSearch =
new RecipeCollection("My recipes", _masterMgr.DataMgr.GetFromData<Recipe>()
.Where(r => r.AuthorMail == MasterManager.CurrentConnectedUser?.Mail)
.ToArray());
_recipeCollectionOnSearch = _masterMgr.GetCurrentUserRecipes();
_allSelectors = ConvertRecipeCollectionInSelectors();
base.Update();
_selectList = SearchInSelection();
if (_selectList.Count == 0)
{
CurrentSelected = default;
return;
}
CurrentSelected = _selectList[CurrentLine].Item;
}
}
}

@ -44,7 +44,7 @@ namespace ConsoleApp.Menu
public override IMenu? Return()
{
if (CurrentSelected == null)
throw new ArgumentNullException("CurrentSelected");
return this;
return new PlainText(CurrentSelected.ToString());
}

@ -75,5 +75,9 @@ namespace Model.Managers
DataMgr.Data[nameof(Recipe)].Add(recipe);
Recipes = DataMgr.GetRecipes();
}
public RecipeCollection GetCurrentUserRecipes()
=> new RecipeCollection("User recipes",
DataMgr.GetRecipes().FindAll(r => r.AuthorMail == CurrentConnectedUser?.Mail).ToArray());
}
}

Loading…
Cancel
Save