public ShoppingListModel(ShoppingList list) { this.InvId = list.Inventory.Id; this.Description = list.Inventory.Item.Description; this.InCart = list.InCart; this.Units = list.Inventory.Unit.Description; this.Quantity = list.QuantityNeeded; this.Size = list.SizeNeeded; }
/// <summary> /// Create a new ShoppingList object. /// </summary> /// <param name="id">Initial value of the Id property.</param> public static ShoppingList CreateShoppingList(global::System.Guid id) { ShoppingList shoppingList = new ShoppingList(); shoppingList.Id = id; return shoppingList; }
/// <summary> /// Deprecated Method for adding a new object to the ShoppingLists EntitySet. Consider using the .Add method of the associated ObjectSet<T> property instead. /// </summary> public void AddToShoppingLists(ShoppingList shoppingList) { base.AddObject("ShoppingLists", shoppingList); }
private void UpdateShoppingList(Inventory inventory) { JourListDMContainer dm = new JourListDMContainer(); var inv = dm.Inventories.Single(z=>z.Id == inventory.Id); bool needmore, needlist; // deal with shopping list if necessary needmore = inv.OnHand < inv.RestockThreshold; needlist = inv.ShoppingList == null; if (needmore) { if (needlist) { // Createlist ShoppingList list = new ShoppingList(); do { list.Id = Guid.NewGuid(); } while (dm.ShoppingLists.Count(z => z.Id == list.Id) > 0); dm.AddToShoppingLists(list); inv.ShoppingList = list; } var log = inv.InventoryLogs.Where(z => z.UnitId == inv.Unit.Id); if (log.Count() > 0) { double sze = (from a in log group a by a.Size into s orderby s.Count() descending select s).First().First().Size; inv.ShoppingList.SizeNeeded = sze; inv.ShoppingList.QuantityNeeded = Math.Round((inv.RequiredQuantity - inv.OnHand) / sze, MidpointRounding.AwayFromZero); } else { inv.ShoppingList.SizeNeeded = (inv.RequiredQuantity - inv.OnHand); inv.ShoppingList.QuantityNeeded = 1; } } else if (!needlist) // Remove the item from the shoppinglist dm.ShoppingLists.DeleteObject(dm.Inventories.First(z => z.ShoppingList.Id == inv.ShoppingList.Id).ShoppingList); dm.SaveChanges(); }