public bool Sync(Dictionary <Guid, bool> products, Guid listId) { var list = from sp in se.ShoppingProduct where sp.ListId == listId select sp; List <ShoppingProduct> p = new List <ShoppingProduct>(); foreach (var item in list) { foreach (var i in products) { if (item.ProductId == i.Key) { item.IsBought = i.Value; ShoppingProduct prod = new ShoppingProduct { ProductId = item.ProductId, ProductName = item.ProductName, IsBought = item.IsBought, ListId = item.ListId }; } } } try { se.SaveChanges(); return(true); } catch (Exception ex) { return(false); } }
public bool AddProductToList(string ProductName, Guid ListId) { Guid id = Guid.NewGuid(); ShoppingProduct lp = new ShoppingProduct { ProductId = id, ProductName = ProductName, ListId = ListId, IsBought = false }; try { se.ShoppingProduct.Add(lp); se.SaveChanges(); return(true); } catch { return(false); } }