Exemplo n.º 1
0
 //Add check out
 public ViewResult Checkout(Cart cart)
 {
     return View(new OrderViewModel
     {
         Cart = cart,
         Order = new Order()
     });
 }
 //Получить корзину из сеанса:
 public Cart GetCart()
 {
     Cart cart = (Cart)Session["Cart"];
     //Если корзины в сеансе нет - создать
     if(cart == null)
     {
         cart = new Cart();
         Session["Cart"] = cart;
     }
     return cart;
 }
 public object BindModel(ControllerContext controllerContext,
 ModelBindingContext bindingContext)
 {
     // get the Cart from the session
     Cart cart = (Cart)controllerContext.HttpContext.Session[sessionKey];
     // create the Cart if there wasn't one in the session data
     if (cart == null)
     {
         cart = new Cart();
         controllerContext.HttpContext.Session[sessionKey] = cart;
     }
     // return the cart
     return cart;
 }
Exemplo n.º 4
0
 public ActionResult Index(Cart cart, string returnUrl)
 {
     if (Session["User"] != null)
     {
         return View(new CartIndexViewModel
         {
             Cart = cart,
             ReturnUrl = returnUrl
         });
     }
     else
     {
         return RedirectToAction("Login", "Account");
     }
 }
Exemplo n.º 5
0
 public RedirectToRouteResult AddToCart(Cart cart, int productId, string returnUrl)
 {
     if (Session["User"] != null)
     {
         Product product = repository.Products
             .FirstOrDefault(p => p.ProductId == productId);
         if (product != null)
         {
             cart.AddItem(product, 1);
         }
         return RedirectToAction("Index", new { returnUrl });
     }
     else
     {
         return RedirectToAction("Login", "Account");
     }
 }
Exemplo n.º 6
0
 public ViewResult Checkout(Cart cart, Order order)
 {
     if (cart.Lines.Count() == 0)
     {
         ModelState.AddModelError("", "Sorry, your cart is empty!");
     }
     order.Datetime = DateTime.Now;
     if (ModelState.IsValid)
     {
         repository2.SaveOrder(order);
         cart.Clear();
         return View("Completed");
     }
     else
     {
         return View(new OrderViewModel
         {
             Cart = cart,
             Order = new Order()
         });
     }
 }
Exemplo n.º 7
0
 private Cart GetCart()
 {
     Cart cart = (Cart)Session["Cart"];
     if (cart == null)
     {
         cart = new Cart();
         Session["Cart"] = cart;
     }
     return cart;
 }
Exemplo n.º 8
0
 //Add new method for summary
 public PartialViewResult Summary(Cart cart)
 {
     return PartialView(cart);
 }
Exemplo n.º 9
0
 public RedirectToRouteResult RemoveFromCart(Cart cart, int productId, string returnUrl)
 {
     Product product = repository.Products
         .FirstOrDefault(p => p.ProductId == productId);
     if (product != null)
     {
         cart.RemoveLine(product);
     }
     return RedirectToAction("Index", new { returnUrl });
 }