|
|
@ -8,9 +8,6 @@ namespace LocalEndpoint
|
|
|
|
internal class AccountRecipesPreferences : IAccountRecipesPreferences
|
|
|
|
internal class AccountRecipesPreferences : IAccountRecipesPreferences
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
//Binds a recipe's id to its amount of person stored in the account's weekly list
|
|
|
|
|
|
|
|
private readonly Dictionary<Guid, uint> weekly = new Dictionary<Guid, uint>();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private readonly Database db;
|
|
|
|
private readonly Database db;
|
|
|
|
public AccountRecipesPreferences(Account account, Database db)
|
|
|
|
public AccountRecipesPreferences(Account account, Database db)
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -43,10 +40,12 @@ namespace LocalEndpoint
|
|
|
|
|
|
|
|
|
|
|
|
public ImmutableList<(RecipeInfo, uint)> GetWeeklyList()
|
|
|
|
public ImmutableList<(RecipeInfo, uint)> GetWeeklyList()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
var weeklyDict = db.GetRecipeListOf(Account.User.Id);
|
|
|
|
List<(RecipeInfo, uint)> weekly = new List<(RecipeInfo, uint)>();
|
|
|
|
List<(RecipeInfo, uint)> weekly = new List<(RecipeInfo, uint)>();
|
|
|
|
|
|
|
|
|
|
|
|
foreach (Recipe recipe in db.ListAllRecipes())
|
|
|
|
foreach (Recipe recipe in db.ListAllRecipes())
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (this.weekly.TryGetValue(recipe.Info.Id, out uint personAmmount))
|
|
|
|
if (weeklyDict.TryGetValue(recipe.Info.Id, out uint personAmmount))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
weekly.Add((recipe.Info, personAmmount));
|
|
|
|
weekly.Add((recipe.Info, personAmmount));
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -70,10 +69,11 @@ namespace LocalEndpoint
|
|
|
|
|
|
|
|
|
|
|
|
public bool AddToWeeklyList(RecipeInfo info, uint persAmount)
|
|
|
|
public bool AddToWeeklyList(RecipeInfo info, uint persAmount)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (weekly.ContainsKey(info.Id))
|
|
|
|
var weeklyDict = db.GetRecipeListOf(Account.User.Id);
|
|
|
|
|
|
|
|
if (weeklyDict.ContainsKey(info.Id))
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
|
|
weekly[info.Id] = persAmount;
|
|
|
|
db.InsertInUserList(Account.User.Id, info.Id, persAmount);
|
|
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|