public IActionResult Checkout(OrderNoRegister order)
        {
            shopCart.listShopItems = shopCart.GetShopItems();

            if (shopCart.listShopItems.Count == 0)
            {
                ModelState.AddModelError("", "Корзина порожня!");
            }

            if (ModelState.IsValid)
            {
                orders.createOrder(order);
                return(RedirectToAction("Complete"));
            }

            return(View(order));
        }
Exemplo n.º 2
0
        public void createOrder(OrderNoRegister orderNoRegister)
        {
            orderNoRegister.orderTime = DateTime.Now;
            context.orderNoRegisters.Add(orderNoRegister);

            var items = shopCart.listShopItems;

            foreach (var item in items)
            {
                var orderDetail = new OrderDetail()
                {
                    GoodsID = item.Goods.id,
                    OrderID = orderNoRegister.id,
                    price   = item.Goods.price
                };
                context.orderDetails.Add(orderDetail);
            }
            context.SaveChanges();
        }