Commit 291e58b5 by Javier Piris

Terminada funcionalidad en el custom MenuViewModel de añadir ingredientes al carito del super

parent 78fbe902
......@@ -21,9 +21,6 @@ namespace inutralia.Models
[JsonProperty("order")]
public int Order { get; set; }
public Ingredient()
{
}
public Ingredient() { }
}
}
......@@ -20,5 +20,7 @@ namespace inutralia.Models
[JsonProperty("fromMenus", Required = Required.Always)]
public bool FromMenus { get; set; }
public ShoppingList() { }
}
}
......@@ -97,6 +97,36 @@ namespace inutralia.API
return retVal;
}
public async Task<int?> UpdateItemIngredientAsync<T>(T item, bool isNew = false) where T : IIdentifiableEntity
{
if (isNew)
{
// Elemento nuevo: asignarle Id. Cogemos la lista de ids ...
List<int> idList = GetIdList(item.GetType());
// ... buscamos el máximo y le sumamos 1
//item.Id = (idList.Count < 1) ? 1 : idList.Max () + 1;
// ... añadimos el nuevo id a la lista
idList.Add(item.Id);
// ... y la guardamos
SetIdList(item.GetType(), idList);
}
else if (!AppSettings.Contains(GetItemPath(item)))
{
// El elemento no es nuevo, pero no existe en los datos guardados
return null;
} //endif
// Guardar elemento
AppSettings.AddOrUpdateValue(GetItemPath(item), JsonConvert.SerializeObject(item));
// Retornar su id
return item.Id;
}
public async Task<int?> UpdateItemAsync<T> (T item, bool isNew = false) where T : IIdentifiableEntity
{
if(isNew)
......@@ -105,7 +135,7 @@ namespace inutralia.API
List<int> idList = GetIdList (item.GetType ());
// ... buscamos el máximo y le sumamos 1
//item.Id = (idList.Count < 1) ? 1 : idList.Max () + 1;
item.Id = (idList.Count < 1) ? 1 : idList.Max () + 1;
// ... añadimos el nuevo id a la lista
idList.Add (item.Id);
......
using inutralia.Models;
using System.Threading.Tasks;
using MvvmHelpers; // Este namespace está en el paquete Refractored.MvvmHelpers
using Xamarin.Forms;
using System;
using System.Collections.Generic;
using System.Linq;
......@@ -318,6 +316,7 @@ namespace inutralia.ViewModels
// Preparar la lista de ingredientes a partir de las recetas seleccionadas
//var ingredients = new HashSet<string>();
var ingredients = new HashSet<Ingredient>();
for (int i = 0; i < _LocalMenu?.DaySelections?.Length; i++)
......@@ -338,7 +337,6 @@ namespace inutralia.ViewModels
// Eliminar de la lista de la compra los ingredientes que no estén en los encontrados
var listaCompra = await App.LocalData.RefreshListAsync<ShoppingList>();
//foreach (var ing in listaCompra.Where(sl => sl.FromMenus && !ingredients.Contains(sl.Text)))
foreach (var ing in listaCompra.Where(sl => sl.FromMenus && !ingredients.Any(o => o.Name.Contains(sl.Text))))
{
......@@ -348,13 +346,13 @@ namespace inutralia.ViewModels
// Añadir a la lista de la compra los que falten
//foreach (string ing in ingredients.Where (i => listaCompra.Find (sl => sl.FromMenus && sl.Text.Equals (i)) == null))
foreach (Ingredient ing in ingredients.Where(i => listaCompra.Find(sl => sl.FromMenus && sl.Text.Equals(i)) == null))
foreach (Ingredient ing in ingredients.Where(i => listaCompra.Find(sl => sl.FromMenus && sl.Text.Equals(i) && sl.Id.Equals(i)) == null))
{
//await App.LocalData.UpdateItemAsync(new ShoppingList() { FromMenus = true, Select = false, Text = ing }, true);
await App.LocalData.UpdateItemAsync(new ShoppingList() { FromMenus = true, Select = false, Text = ing.Name, Id = ing.Id }, true);
} //endforeach
await App.LocalData.UpdateItemAsync(_LocalMenu);
await App.LocalData.UpdateItemIngredientAsync(_LocalMenu);
IsBusy = false;
......@@ -371,6 +369,8 @@ namespace inutralia.ViewModels
{
foreach (var ing in recipes[index].Ingredients)
{
// Lambda que elimina los ingredientes que se repiten al añadir recetas
if (!ingredients.Any(o => o.Name.Contains(ing.Name)))
//ingredients.Add (ing.Name);
ingredients.Add(new Ingredient() { Name = ing.Name, Id = ing.Id });
} //endforeach
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment