public RedirectToActionResult AddToShoppingCart(int drinkId)
        {
            var selectedDrink = _drinRepository.Drinks().FirstOrDefault(p => p.DrinkId == drinkId);

            if (selectedDrink != null)
            {
                _shoppingCart.AddToCart(selectedDrink, 1);
            }
            return(RedirectToAction("Index"));
        }
Exemplo n.º 2
0
        public ViewResult List(string category)
        {
            string _category = category;
            IEnumerable <Drink> drinks;

            string currentCategory = string.Empty;

            if (string.IsNullOrEmpty(category))
            {
                drinks          = _drinkRepository.Drinks().OrderBy(n => n.DrinkId);
                currentCategory = "All drinks";
            }
            else
            {
                if (string.Equals("Alcoholic", _category, StringComparison.OrdinalIgnoreCase))
                {
                    drinks = _drinkRepository.Drinks().Where(p =>
                                                             p.Category.CategoryName.Equals("Alcoholic")).OrderBy(p => p.Name);
                }
                else
                {
                    drinks = _drinkRepository.Drinks().Where(p =>
                                                             p.Category.CategoryName.Equals("Non-alcoholic")).OrderBy(p => p.Name);
                }

                currentCategory = _category;
            }

            var drinkListViewModel = new DrinkListViewModel
            {
                Drinks          = drinks,
                CurrentCategory = currentCategory
            };

            return(View(drinkListViewModel));
        }