Пример #1
0
        public void Buy(Purchase newPurchase, User buyer)
        {
            using (IDocumentSession session = DocumentStore.OpenSession())
            {
                Item loadedItem = session.Load<Item>(newPurchase.Item.Id);
                loadedItem.Sold += newPurchase.Quantity;
                loadedItem.Stock -= newPurchase.Quantity;

                User loadedUser = session.Load<User>(buyer.Id);
                loadedUser.ItemPurchases.Add(new Purchase
                    {
                        ItemId = loadedItem.Id,
                        Quantity = newPurchase.Quantity,
                        Timestamp = newPurchase.Timestamp
                    });
                loadedUser.Bill += loadedItem.Price*newPurchase.Quantity;
                session.SaveChanges();
            }
        }
Пример #2
0
 private void AddToBasket(Item item, int multiplier)
 {
     try
     {
         var existingPurchase = CheckOutList.First(p => p.Item.Barcode == item.Barcode);
         existingPurchase.Quantity += multiplier;
         CheckOutList.Remove(existingPurchase);
         CheckOutList.Insert(0, existingPurchase);
     }
     catch
     {
         Purchase purchase = new Purchase { Item = item, Quantity = multiplier, Timestamp = DateTime.Now };
         CheckOutList.Insert(0, purchase);
     }
 }