public ActionResult Payment(int MaKH)
        {
            var order = new DonDatHang();

            order.NgayDat   = DateTime.Now;
            order.NgayGiao  = DateTime.Now.AddDays(3);
            order.TinhTrang = true; //đã nhận hàng
            order.MaKH      = MaKH;

            try
            {
                //thêm dữ liệu vào đơn đặt hàng
                var result1 = new OrderProcess().Insert(order);

                var     cart    = (List <CartModel>)Session[CartSession];
                var     result2 = new OderDetailProcess();
                decimal?total   = 0;
                foreach (var item in cart)
                {
                    var orderDetail = new ChiTietDDH();
                    orderDetail.MaSach  = item.sach.MaSach;
                    orderDetail.MaDDH   = result1;
                    orderDetail.SoLuong = item.Quantity;
                    orderDetail.DonGia  = item.sach.GiaBan;
                    result2.Insert(orderDetail);

                    total = cart.Sum(x => x.Total);
                }
            }
            catch (Exception)
            {
                return(Redirect("~/Cart/Error"));
            }
            Session[CartSession] = null;
            return(Redirect("~/Cart/Success"));
        }
示例#2
0
        public ActionResult Payment(int MaKH, FormCollection f)
        {
            var PMethod       = int.Parse(f["PaymentMethod"]);
            var vanChuyen     = int.Parse(f["vanChuyen"]);
            var tienVanChuyen = vanChuyen == 0 ? Convert.ToDecimal(20000) : Convert.ToDecimal(40000);
            var order         = new DonDatHang();

            order.NgayDat   = DateTime.Now;
            order.NgayGiao  = DateTime.Now.AddDays(3);
            order.TinhTrang = true; //đã nhận hàng
            order.MaKH      = MaKH;

            try
            {
                if (PMethod == 1)
                {
                    //thêm dữ liệu vào đơn đặt hàng
                    order.ThanhToan = 1;
                    var     result1 = new OrderProcess().Insert(order);
                    var     cart    = (List <CartModel>)Session[CartSession];
                    var     result2 = new OderDetailProcess();
                    decimal?total   = 0;
                    foreach (var item in cart)
                    {
                        var orderDetail = new ChiTietDDH();
                        orderDetail.MaSach  = item.sach.MaSach;
                        orderDetail.MaDDH   = result1;
                        orderDetail.SoLuong = item.Quantity;
                        orderDetail.DonGia  = item.sach.GiaBan;
                        result2.Insert(orderDetail);

                        total = cart.Sum(x => x.Total);
                    }

                    Session[CartSession] = null;
                    return(Redirect("/Cart/Success"));
                }
                else
                {
                    order.ThanhToan = 0;
                    var     result1 = new OrderProcess().Insert(order);
                    var     cart    = (List <CartModel>)Session[CartSession];
                    var     result2 = new OderDetailProcess();
                    decimal?total   = 0;
                    foreach (var item in cart)
                    {
                        var orderDetail = new ChiTietDDH();
                        orderDetail.MaSach  = item.sach.MaSach;
                        orderDetail.MaDDH   = result1;
                        orderDetail.SoLuong = item.Quantity;
                        orderDetail.DonGia  = item.sach.GiaBan;
                        result2.Insert(orderDetail);

                        total = cart.Sum(x => x.Total);
                    }

                    Session[CartSession] = null;
                    return(Redirect(ThanhToanMoMo(result1.ToString(),
                                                  total.ToString().Substring(0, total.ToString().Length - 5))));
                }
            }
            catch (Exception)
            {
                return(Redirect("/Cart/Error"));
            }
        }
示例#3
0
        //GET : /Admin/Home/DetailsOrder : trang xem chi tiết đơn hàng
        public ActionResult DetailsOrder(int id)
        {
            var result = new OderDetailProcess().ListDetail(id);

            return(View(result));
        }