Exemplo n.º 1
0
        public void AddToCart(Drink drink, int amount)
        {
            var shoppingCartItem = context.tblshoppingCartItems
                                   .SingleOrDefault(s => s.Drink.DrinkID == drink.DrinkID && s.ShoppingCartID == ShoppingCartID);

            if (shoppingCartItem == null)
            {
                shoppingCartItem = new ShoppingCartItem
                {
                    ShoppingCartID = ShoppingCartID,
                    Drink          = drink,
                    Amount         = 1
                };
                context.tblshoppingCartItems.Add(shoppingCartItem);
            }
            else
            {
                shoppingCartItem.Amount++;
            }
            context.SaveChanges();
        }
Exemplo n.º 2
0
        public void CreateOrder(Order order)
        {
            order.OrderPlaced = DateTime.Now;
            _dayAndNigthDbContext.tblorders.Add(order);

            var shoppingCartItems = _shoppingCart.ShoppingCartItems;

            foreach (var item in shoppingCartItems)
            {
                var orderDetail = new OrderDetail
                {
                    Amount  = item.Amount,
                    DrinkID = item.Drink.DrinkID,
                    OrderID = order.OrderID,
                    Price   = item.Drink.Price
                };
                _dayAndNigthDbContext.tblorderDetails.Add(orderDetail);
            }

            _dayAndNigthDbContext.SaveChanges();
        }