示例#1
0
        //
        // GET: /ShoppingCart/

        public ActionResult Index()
        {
            var cart = _shoppingCartFactory.GetCart();

            // Set up our ViewModel
            var viewModel = new ShoppingCartViewModel
            {
                CartItems = cart.GetCartItems(),
                CartTotal = cart.GetTotal()
            };

            // Return the view
            return(View(viewModel));
        }
        private void MigrateShoppingCart(string UserName)
        {
            // Associate shopping cart items with logged-in user
            var cart = _shoppingCartFactory.GetCart();

            cart.MigrateCart(UserName);
            Session[ShoppingCartFactory.CartSessionKey] = UserName;
        }
        //
        // POST: /Account/Register
        private void MigrateShoppingCart(string UserName)
        {
            // Associate shopping cart items with logged-in user
            ShoppingCart cart = _shoppingCartFactory.GetCart(this.HttpContext);

            cart.MigrateCart(UserName);
            //Session[ShoppingCart.CartSessionKey] = UserName;
            _sessionProvider[ShoppingCart.CartSessionKey] = UserName;
        }
        public void TestInitialize()
        {
            _securityProvider = Substitute.For<IWebSecurityProvider>();
            _session = Substitute.For<ISessionProvider>();
            _carts = Substitute.For<ICartRepository>();
            _shoppingCartFactory = Substitute.For<IShoppingCartFactory>();

            _shoppingCart = new ShoppingCart(Substitute.For<IUnitOfWork>(), _carts,
                                    Substitute.For<IAlbumsRepository>(), Substitute.For<IOrderDetailRepository>());

            _carts.Get().Returns(new List<Cart> { new Cart { CartId = "CartA" }, new Cart { CartId = "CartB" } }.AsQueryable());

            _shoppingCartFactory.GetCart(null as HttpContextBase).Returns(_shoppingCart);

        }
        public void TestInitialize()
        {
            _securityProvider    = Substitute.For <IWebSecurityProvider>();
            _session             = Substitute.For <ISessionProvider>();
            _carts               = Substitute.For <ICartRepository>();
            _shoppingCartFactory = Substitute.For <IShoppingCartFactory>();

            _shoppingCart = new ShoppingCart(Substitute.For <IUnitOfWork>(), _carts,
                                             Substitute.For <IAlbumsRepository>(), Substitute.For <IOrderDetailRepository>());

            _carts.Get().Returns(new List <Cart> {
                new Cart {
                    CartId = "CartA"
                }, new Cart {
                    CartId = "CartB"
                }
            }.AsQueryable());

            _shoppingCartFactory.GetCart(null as HttpContextBase).Returns(_shoppingCart);
        }
        public ActionResult AddressAndPayment(FormCollection values)
        {
            var order = new Order();

            TryUpdateModel(order);

            try
            {
                if (string.Equals(values["PromoCode"], PromoCode,
                                  StringComparison.OrdinalIgnoreCase) == false)
                {
                    return(View(order));
                }
                else
                {
                    order.Username  = User.Identity.Name;
                    order.OrderDate = DateTime.Now;

                    //Save Order
                    _storeDB.Orders.Add(order);
                    _storeDB.SaveChanges();

                    //Process the order
                    var cart = _shoppingCartFactory.GetCart();
                    cart.CreateOrder(order);

                    return(RedirectToAction("Complete",
                                            new { id = order.OrderId }));
                }
            }
            catch
            {
                //Invalid - redisplay with errors
                return(View(order));
            }
        }