예제 #1
0
        public ActionResult Payment(string customername, string customerphone, string customeraddress, decimal totalprice)
        {
            var order = new Order();

            order.OrderDate   = DateTime.Now;
            order.ShipAddress = customeraddress;
            order.TotalPrice  = totalprice;
            Account acc = (Account)Session[Common.Session.LoginSession];

            if (acc != null)
            {
                order.CustomerEmail = acc.Email;
            }

            try
            {
                var id   = new OrderF().Insert(order);
                var cart = (List <CartItem>)Session[Common.Session.CartSession];

                var odf = new OrderDetailF();
                foreach (var item in cart)
                {
                    var od = new OrderDetail();
                    od.OrderID   = id;
                    od.ProductID = item.Product.ID;
                    od.UnitPrice = item.Product.Price;
                    od.Quantity  = item.Quantity;
                    odf.Insert(od);
                }
            }
            catch { }

            return(RedirectToAction("Index", "Home"));
        }
예제 #2
0
        public JsonResult Payment(string shipName, string mobile, string address, string email, double tongtien)
        {
            var order = new Order();

            order.OrderDate = DateTime.Now;
            order.Address   = address;
            order.Phone     = mobile;
            order.Receiver  = shipName;
            order.Email     = email;
            order.Amount    = tongtien;
            MyContext context = new MyContext();
            Account   acc     = (Account)Session[Common.Session.USER_SESSION];

            order.Customer  = acc.UserName;
            order.TinhTrang = 0;
            try
            {
                var id = new OrderF().Insert(order);

                var cart = (Cart)Session[Common.Session.CART_SESSION];

                var detailDao = new OrderDetailF();

                foreach (var item in cart.Lines)
                {
                    var orderDetail = new OrderDetail();
                    orderDetail.IdProduct = item.Sanpham.maSanPham;
                    orderDetail.IdOrder   = id;
                    orderDetail.Quantity  = item.Quantity;
                    orderDetail.Amount    = item.Sanpham.giaSanPham * item.Quantity;
                    detailDao.Insert(orderDetail);


                    var sp = context.Products.Find(item.Sanpham.maSanPham);
                    sp.Quantity -= item.Quantity;
                    context.SaveChanges();
                }
                Session[Common.Session.CART_SESSION] = null;
                return(Json(new
                {
                    status = true
                }));
            }
            catch
            {
                return(Json(new
                {
                    status = false
                }));
            }
            // return RedirectToAction("Index", "Home");
        }