public void AddToCart(Drink drink, int amount) { var shoppingCartItem = _pubPlazaContext.ShoppingCartItems. SingleOrDefault(s => s.Drink.DrinkId == drink.DrinkId && s.ShoppingCartId == ShoppingCartId); if (shoppingCartItem == null) { shoppingCartItem = new ShoppingCartItem { ShoppingCartId = ShoppingCartId, Drink = drink, Amount = amount }; _pubPlazaContext.ShoppingCartItems.Add(shoppingCartItem); } else { shoppingCartItem.Amount++; } _pubPlazaContext.SaveChanges(); }
public void CreateOrder(Order order) { try { order.OrderPlaced = DateTime.Now; _pubplazacontext.Orders.Add(order); var shoppingCartItems = _shoppingcart.ShoppingCartItems; foreach (var item in shoppingCartItems) { OrderDetail orderDetail = new OrderDetail() { DrinkId = item.Drink.DrinkId, Price = (int)item.Drink.Price, Ammount = item.Amount, OrderId = order.OrderId }; _pubplazacontext.OrderDetails.Add(orderDetail); } _pubplazacontext.SaveChanges(); } catch (Exception e) { } }