コード例 #1
0
        public ActionResult DetailsPayment(DetailsPayment model)
        {
            if (ModelState.IsValid)
            {
                ShoppingCartBLL shoppingBLL = ShoppingCartBLL.GetCart(this.HttpContext);
                DonDatHang order = shoppingBLL.CreateOrder(model, this.User.Identity.Name);
                OrderService service = new OrderService();
                int id = service.CreateOrder(order);
                if (id > 0)
                {
                    shoppingBLL.EmptyCart();
                    return RedirectToAction("Complete", new { id = id });
                }
                ModelState.AddModelError("", "Tạo đơn hàng thất bại, vui lòng thử lại!");
            }

            var cart = ShoppingCartBLL.GetCart(this.HttpContext);
            var shoppingCart = new ShoppingCart
            {
                CartItems = cart.GetCartItems(),
                CartTotal = cart.GetTotal()
            };

            ViewBag.Cart = shoppingCart;

            return View(model);
        }
コード例 #2
0
        public DonDatHang CreateOrder(DetailsPayment details, string username)
        {
            NguoiNhan receiver = details.Receiver;

            DonDatHang order = new DonDatHang();
            order.NguoiNhan = receiver;
            order.MaPTGH = details.MaPTGH;
            order.MaPTTT = details.MaPTTT;
            order.MaTK = username;
            order.NgayLap = DateTime.Now;
            order.DonGia = 0;
            order.MaTrangThai = "CGTT";

            var cartItems = GetCartItems();
            order.ChiTietDonHangs = new List<ChiTietDonHang>();
            double total = 0;
            foreach (var item in cartItems)
            {
                var detailsOrder = new ChiTietDonHang
                {
                    MaDDH = order.MaDDH,
                    MaSP = item.MaSP,
                    SoLuong = item.SoLuong,
                    Gia = item.SanPham.GiaBanHienHanh
                };
                total += item.SanPham.GiaBanHienHanh;
                order.ChiTietDonHangs.Add(detailsOrder);
            }
            order.DonGia = total;

            return order;
        }