public void AddCart(Pie pie, int amount) { var shoppingCartItem = _walloniaPastryShopDbContext.ShoppingCartItems .SingleOrDefault(s => s.Pie.PieId == pie.PieId && s.ShoppingCartId == ShoppingCartId); if (shoppingCartItem == null) { shoppingCartItem = new ShoppingCartItem { Pie = pie, ShoppingCartId = ShoppingCartId, Amount = amount }; _walloniaPastryShopDbContext.ShoppingCartItems.Add(shoppingCartItem); } else { shoppingCartItem.Amount++; } _walloniaPastryShopDbContext.SaveChanges(); }
public void CreateOrder(Order order) { order.OrderPlaced = DateTime.Now; _walloniaPastryShopDbContext.Add(order); var shoppingCartItems = _shoppingCart.ShoppingCartItems; foreach (var shoppingItem in shoppingCartItems) { var orderDetail = new OrderDetail { Amount = shoppingItem.Amount, OrderId = order.OrderId, PieId = shoppingItem.Pie.PieId, Price = shoppingItem.Pie.Price }; _walloniaPastryShopDbContext.OrderDetails.Add(orderDetail); } _walloniaPastryShopDbContext.SaveChanges(); }