Exemplo n.º 1
0
        public void CreateOrder(Order order)
        {
            order.OrderPlaced = DateTime.Now;
            db.orders.Add(order);
            foreach (var item in shoppinCartRepo.ViewShoppingCart())
            {
                DrinkOrder drinkOrder = new DrinkOrder
                {
                    DrinkId = item.Drink.DrinkId,
                    OrderId = order.OrderId,
                    Amount  = item.amount,
                    Price   = item.Drink.Price * item.amount
                };
                db.drinkOrders.Add(drinkOrder);
            }

            if (db.SaveChanges() < 0)
            {
                foreach (var item in shoppinCartRepo.ViewShoppingCart())
                {
                    item.Drink.Stock += item.amount;
                }
                db.SaveChanges();
            }
        }
Exemplo n.º 2
0
        public IActionResult Index()
        {
            ViewBag.SessionId = SessionId;
            CartViewModel cartModel = new CartViewModel
            {
                cartItems = shoppinCartRepo.ViewShoppingCart(),
                CartTotal = shoppinCartRepo.GetCartTotal()
            };

            return(View(cartModel));
        }