Esempio n. 1
0
        //
        // 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");
        }
Esempio n. 2
0
        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;
        }
Esempio n. 3
0
 public ActionResult Summary(Cart cart)
 {
     ViewData["CartCount"] = cart.GetCount();
     return PartialView("_Summary");
 }
Esempio n. 4
0
 //
 // GET: /Cart/RemoveItem
 public ActionResult RemoveItem(Cart cart, int id)
 {
     CartService.RemoveItem(cart.Id, id);
     return RedirectToAction("Index");
 }
Esempio n. 5
0
 //
 // GET: /Cart/
 // GET: /Cart/Index
 public ActionResult Index(Cart cart)
 {
     var model = AutoMapper.Mapper.Map(cart, new CartViewModel());
     return View(model);
 }
Esempio n. 6
0
        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);
        }
Esempio n. 7
0
        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);
        }