public ActionResult Checkout(string shipName, string mobile, string address, string email) { var session = (UserLogin)Session[GamingShop.Common.CommonConstants.USER_SESSION]; var userController = new MoUserController(); var order = new Order(); if (session != null) { var user = userController.GetById(session.UserName); order.ID = user.ID; order.CreatedDate = DateTime.Now; order.ShipAddress = user.Address; order.ShipName = user.Name; order.ShipEmail = user.Email; order.ShipMobile = user.Phone; } else { order.CreatedDate = DateTime.Now; order.ShipAddress = address; order.ShipName = shipName; order.ShipEmail = email; order.ShipMobile = mobile; } try { var id = new MoOrderController().Insert(order); var cart = (List <CartItem>)Session[CartSession]; var detail = new MoOrderDetailController(); foreach (var item in cart) { var orderDetail = new OrderDetail(); orderDetail.ProductID = item.Product.ID; orderDetail.OrderID = id; orderDetail.Price = item.Product.Price; orderDetail.Quantity = item.Quantity; detail.Insert(orderDetail); } } catch (Exception ex) { return(Redirect("/CheckoutError")); } return(RedirectToAction("Success")); }
public ActionResult Checkout() { var cart = Session[CartSession]; var list = new List <CartItem>(); var session = (UserLogin)Session[GamingShop.Common.CommonConstants.USER_SESSION]; if (session != null) { var userController = new MoUserController(); var user = userController.GetById(session.UserName); ViewBag.User = user; } if (cart != null) { list = (List <CartItem>)cart; } return(View(list)); }