Пример #1
0
        //bấm nút thanh toán, nó sẽ lưu vào csdl và giỏ hàng sẽ trở về số 0
        public ActionResult Checkout(decimal totalPrice)
        {
            var c  = Session["cart"] as ClientCart;
            var ui = Session["Logged"] as ClientUserInfo;

            var user  = CSDLQLBH.UserGetSingleByUserName(ui.Username);
            var order = new ClientOrder
            {
                OrderDate = DateTime.Now,
                User      = user,
                Total     = totalPrice,
            };

            var totalOrders = CSDLQLBH.GetOrders().ToList().Count;

            if (totalOrders == 0)
            {
                order.OrderID = 1;
            }
            CSDLQLBH.InsertOrders(order);

            decimal amount = 0;

            foreach (var ci in c.Items)
            {
                var p = CSDLQLBH.GetSingleProduct(ci.Product.ProID);
                amount = (decimal)p.Price * ci.Quantity;
                var od = new ClientOrderDetail
                {
                    Order    = order,
                    Product  = p,
                    Quantity = ci.Quantity,
                    Price    = (decimal)p.Price,
                    Amount   = amount
                };
                CSDLQLBH.InsertOrderDetail(od);
                p.Quantity -= ci.Quantity;
                CSDLQLBH.UpdateProduct(p);
            }

            c = CSDLQLBH.Checkout(c);
            Session["CheckOut"] = 1;
            return(RedirectToAction("Detail", "Cart"));
        }
        // GET: ManageOrder
        public ActionResult Index()
        {
            var l = CSDLQLBH.GetOrders(sort: "OrderDate DESC");

            return(View(l.ToList()));
        }