public ActionResult Index(FormCollection data) { var cart = Session[Constant.Cart]; var couponCode = Session[Constant.Code]; var cartItems = (List <CartItem>)cart; var coupon = _coupon.GetById(couponCode); var fullName = data["fullName"]; var phone = data["phone"]; var address = data["address"]; var description = data["description"]; var userId = Session["userId"]; User user = _user.GetById(userId); List <OrderDetail> orderDetails = new List <OrderDetail>(); foreach (var item in cartItems) { var orderDetail = new OrderDetail() { ProductDetail = item.ProductDetail, Quantity = item.Quantity }; orderDetails.Add(orderDetail); } if (coupon == null) { coupon = _coupon.GetById("KHONGGIAMGIA"); } var order = new Order() { FullName = fullName, Address = address, Phone = phone, Description = description, Coupon = coupon, Status = Status.waitForConfirm, User = user }; _checkOut.CheckOut(order, orderDetails); cartItems.Clear(); Session[Constant.Code] = null; return(RedirectToAction("CheckOutIsOk")); }
public ActionResult CheckOut(FormCollection fc) { Cart cart = Session["Cart"] as Cart; var order = new Order(); string name = fc["name"]; string phone = fc["phone"]; string address = fc["address"]; string email = fc["email"]; var coupon = _couponServices.GetById(Session["Codee"]); var userId = Session["iduser"]; User user = _userServices.GetById(userId); if (coupon == null) { coupon = _couponServices.GetById("khonggiamgia"); } if (Session["iduser"] == null) { order = new Order() { OrderDate = DateTime.Now, Status = Status.ChoXacNhan, ToAddr = address, ToName = name, ToPhone = phone, Coupon = coupon, }; } else { order = new Order() { OrderDate = DateTime.Now, Status = Status.ChoXacNhan, ToAddr = address, ToName = name, ToPhone = phone, Coupon = coupon, User = user, }; } // add orderDetail List <OrderDetail> ord = new List <OrderDetail>(); foreach (var item in cart.Items) { var pro = _productServices.GetById(item._product.ProductID); if (item._quatity > pro.Quantity) { ViewBag.Er = "Sản phẩm " + pro.ProductName + " chỉ còn " + pro.Quantity + "!! Vui lòng cập nhật lại số lượng"; return(View(cart)); } var orderDetail = new OrderDetail() { OrderID = order.OrderID, ProductID = item._product.ProductID, Quantity = item._quatity, }; ord.Add(orderDetail); } _checkOutServices.CheckOut(order, ord); Session["Cart"] = null; Session["Codee"] = null; Session["Value"] = null; return(RedirectToAction("CheckOutSuccess")); }