//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;
 }
 public ActionResult Index(Cart cart, string returnUrl)
 {
     if (Session["User"] != null)
     {
         return View(new CartIndexViewModel
         {
             Cart = cart,
             ReturnUrl = returnUrl
         });
     }
     else
     {
         return RedirectToAction("Login", "Account");
     }
 }
 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");
     }
 }
 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()
         });
     }
 }
 private Cart GetCart()
 {
     Cart cart = (Cart)Session["Cart"];
     if (cart == null)
     {
         cart = new Cart();
         Session["Cart"] = cart;
     }
     return cart;
 }
 //Add new method for summary
 public PartialViewResult Summary(Cart cart)
 {
     return PartialView(cart);
 }
 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 });
 }