Esempio n. 1
0
        public ActionResult Index()
        {
            var model = new ShoppingCartIndexViewModel();

            var cart = Session["cart"] as ShoppingCartModel ?? new ShoppingCartModel();

            model.Products = cart.Products;

            return(View(model));
        }
Esempio n. 2
0
        public ActionResult IndexPost(ShoppingCartIndexViewModel model, string Checkout)
        {
            if (model.CartItems != null)
            {
                UpdateCart(model.CartItems);
            }

            if (_locationService != null && model.CountryId > 0)
            {
                var country = _locationService.GetCountry(model.CountryId);

                if (country != null && country.Enabled)
                {
                    _shoppingCartService.SetProperty("CountryId", country.Id);
                    var state = country.States.Where(s => s.Id == model.StateId && s.Enabled).FirstOrDefault();
                    if (state != null)
                    {
                        _shoppingCartService.SetProperty("StateId", state.Id);
                    }
                    else
                    {
                        _shoppingCartService.RemoveProperty("StateId");
                    }
                }
                else
                {
                    _shoppingCartService.RemoveProperty("CountryId");
                    _shoppingCartService.RemoveProperty("StateId");
                }
            }

            if (_shippingService != null)
            {
                if (model.ShippingProviderId > 0)
                {
                    _shoppingCartService.SetProperty("ShippingProviderId", model.ShippingProviderId);
                }
                else
                {
                    _shoppingCartService.RemoveProperty("ShippingProviderId");
                }
            }

            if (!String.IsNullOrEmpty(Checkout))
            {
                var checkoutProvider = _checkoutProviders.Where(cp => cp.Name == Checkout).OrderByDescending(cp => cp.Priority).FirstOrDefault();
                if (checkoutProvider != null && checkoutProvider.CheckoutRoute != null)
                {
                    return(RedirectToRoute(checkoutProvider.CheckoutRoute));
                }
            }

            return(Index());
        }
        public IViewComponentResult Invoke()
        {
            _shoppingCartService.ShoppingCartItems = _shoppingCartService.GetShoppingCartItemsAsync();
            var model = new ShoppingCartIndexViewModel
            {
                ShoppingCart      = _shoppingCartService,
                ShoppingCartTotal = _shoppingCartService.GetShoppingCartTotalAsync()
            };

            return(View(model));
        }
Esempio n. 4
0
        public IViewComponentResult Invoke()
        {
            _shoppingCart.ShoppingCartItems = _shoppingCart.GetShoppingCartItems();

            var shoppingCartIndexViewModel = new ShoppingCartIndexViewModel
            {
                ShoppingCart      = _shoppingCart,
                ShoppingCartTotal = _shoppingCart.GetShoppingCartTotal()
            };

            return(View(shoppingCartIndexViewModel));
        }
Esempio n. 5
0
        public IViewComponentResult Invoke()
        {
            var items = this._shoppingCartService.GetShoppingCartItemsAsync();

            this._shoppingCartService.ShoppingCartItems = items.Result;

            var viewModel = new ShoppingCartIndexViewModel
            {
                Items             = this._mapper.Map <List <ShoppingCartItemViewModel> >(items.Result),
                ShoppingCartTotal = _shoppingCartService.GetShoppingCartTotalAsync().Result
            };

            return(View(viewModel));
        }
Esempio n. 6
0
        public async Task <IActionResult> Index()
        {
            var items = await _shoppingCartService.GetShoppingCartItemsAsync();

            _shoppingCartService.ShoppingCartItems = items;

            var shoppingCartViewModel = new ShoppingCartIndexViewModel
            {
                Items             = this._mapper.Map <List <ShoppingCartItemViewModel> >(items),
                ShoppingCartTotal = await _shoppingCartService.GetShoppingCartTotalAsync()
            };

            return(View(shoppingCartViewModel));
        }
Esempio n. 7
0
        public static ShoppingCartIndexViewModel GetAllByCategory(DatabaseContext db, string category)
        {
            var mainShoppingCart = db.ShoppingCarts.First();
            var movies           = mainShoppingCart.Movies.AsQueryable();

            var viewModel = new ShoppingCartIndexViewModel
            {
                Movies = MovieHelper.GetMovies(movies, category),
                AvailableCategories = MovieHelper.GetCategories(movies).ToList(),
                SelectedCategory    = category
            };

            return(viewModel);
        }
        public IActionResult Index(bool isValidAmount = true, string returnUrl = "/")
        {
            _shoppingCart.GetShoppingCartItems();
            var model = new ShoppingCartIndexViewModel
            {
                ShoppingCart      = _shoppingCart,
                ShoppingCartTotal = _shoppingCart.GetShoppingCartTotal(),
                ReturnUrl         = returnUrl
            };

            if (!isValidAmount)
            {
                ViewBag.InvalidAmountText = "*There were not enough items in stock to add*";
            }
            return(View(model));
        }
Esempio n. 9
0
        public async Task ShoppingCartIndex()
        {
            // Arrange
            ShoppingCartController controller = new ShoppingCartController(shoppingCartService.Object, catalogService.Object, financeService.Object);

            // Act
            ViewResult result = await controller.Index() as ViewResult;

            // Assert
            Assert.IsNotNull(result);
            ShoppingCartIndexViewModel model = result.Model as ShoppingCartIndexViewModel;
            List <CartItem>            items = model.Cart.Items.ToList();

            Assert.AreEqual(2, items.Count);
            Assert.AreEqual("1", items[0].ProductId);
            Assert.AreEqual("2", items[1].ProductId);
        }
Esempio n. 10
0
        public IActionResult Index()
        {
            var userId = this.userManager.GetUserId(this.User);

            var shoppingCartItems = this.shoppingCartItemsService.GetAllShoppingCartItems <ShoppingCartItemViewModel>(userId);

            if (shoppingCartItems == null)
            {
                return(this.RedirectToAction("Index", "Home"));
            }

            var model = new ShoppingCartIndexViewModel()
            {
                ShoppingCartItems = shoppingCartItems,
                LatestProducts    = this.productService.GetLatestProducts <HomeIndexProductViewModel>(20),
            };

            return(this.View(model));
        }
Esempio n. 11
0
        public ActionResult Index(ShoppingCartIndexViewModel model)
        {
            model.CartItems = _cartService.GetCartWithAssociatedProducts(this._shoppingCartID).ToList();

            if (!String.IsNullOrEmpty(model.PostalCode))
            {
                //TODO calculate actual shipping
                //modelShippingCost = _shippingService.CalculateShipping(model.CartItems);
                model.ShippingCost = 5.00m;
            }

            if (model.PromoCodes.Any())
            {
                //
            }

            model.ShoppingCartTotalPrice = model.CartItems.Sum(ci => ci.Quantity * ci.Product.UnitPrice) + model.ShippingCost;

            return(View(model));
        }
Esempio n. 12
0
        //
        // GET: /ShoppingCart/
        public ActionResult Index()
        {
            object importantCartUpdates;

            TempData.TryGetValue("ImportantCartUpdates", out importantCartUpdates);

            object existingModelState;

            if (TempData.TryGetValue("ModelState", out existingModelState))
            {
                this.ModelState.Merge((ModelStateDictionary)existingModelState);
            }

            var model = new ShoppingCartIndexViewModel();

            model.CartItems              = _cartService.GetCartWithAssociatedProducts(this._shoppingCartID).ToList();
            model.ImportantCartUpdates   = importantCartUpdates as List <String> ?? new List <String>();
            model.ShoppingCartTotalPrice = model.CartItems.Sum(ci => ci.Quantity * ci.Product.UnitPrice);

            return(View(model));
        }
Esempio n. 13
0
        //
        // GET: /ShoppingCart/
        public ActionResult Index()
        {
            IEnumerable <CartItem> cartItems =
                _shoppingCartService.GetCartWithProducts(Utility.Helpers.ShoppingCartHelpers.GetShoppingCartId(this.ControllerContext));

            //TODO refresh cart items/do updates with messages..no longer available etc

            ShoppingCartIndexViewModel model = new ShoppingCartIndexViewModel()
            {
                CartItems = cartItems.ToList()
            };

            Object cartUpdates;

            if (TempData.TryGetValue(KeyTempDataCartUpdates, out cartUpdates))
            {
                model.CartUpdates.AddRange(cartUpdates as IEnumerable <String>);
            }

            return(View(model));
        }