// // GET: /Cart/AddItem public ActionResult AddItem(Cart cart, int id) { var product = CatalogService.GetProduct(id); if (product != null) { CartService.AddItem(cart.Id, product.Id); } return RedirectToAction("Index"); }
public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext) { // get the CartId from the session string cartId = getCartId(controllerContext.HttpContext); var service = DependencyResolver.Current.GetService<ICartService>(); // create the Cart var cart = new Cart { Id = cartId, Items = service.GetCartItems(cartId) }; // return the cart return cart; }
public ActionResult Summary(Cart cart) { ViewData["CartCount"] = cart.GetCount(); return PartialView("_Summary"); }
// // GET: /Cart/RemoveItem public ActionResult RemoveItem(Cart cart, int id) { CartService.RemoveItem(cart.Id, id); return RedirectToAction("Index"); }
// // GET: /Cart/ // GET: /Cart/Index public ActionResult Index(Cart cart) { var model = AutoMapper.Mapper.Map(cart, new CartViewModel()); return View(model); }
public ActionResult Register(RegisterViewModel model, Cart cart) { if (ModelState.IsValid) { // Attempt to register the user try { WebSecurity.CreateUserAndAccount(model.UserName, model.Password, new { CreatedDate = DateTime.Now, Email = model.Email, Name = model.Name }); WebSecurity.Login(model.UserName, model.Password); // Associate cart items with logged-in user CartService.MigrateCart(cart.Id, model.UserName); return RedirectToLocal(null); } catch (MembershipCreateUserException e) { ModelState.AddModelError("", ErrorCodeToString(e.StatusCode)); } } // If we got this far, something failed, redisplay form return View(model); }
public ActionResult Login(LoginViewModel model, Cart cart, string returnUrl) { if (ModelState.IsValid) { string userName; if (model.UserName.Contains("@")) { userName = UserService.GetUserNameByEmail(model.UserName); } else { userName = model.UserName; } if (WebSecurity.Login(userName, model.Password, persistCookie: model.RememberMe)) { // Associate cart items with logged-in user CartService.MigrateCart(cart.Id, userName); return RedirectToLocal(returnUrl); } } // If we got this far, something failed, redisplay form ModelState.AddModelError("", "The user name or password provided is incorrect."); return View(model); }