示例#1
0
        public ViewResult List()
        {
            ViewBag.Name = "DotNet,How?";
            DrinksListViewModel vm = new DrinksListViewModel();

            vm.Drinks          = _drinkRepository.Drinks;
            vm.CurrentCategory = "DrinkCategory";

            return(View(vm));
            //string _category = category;
            //IEnumerable<Drink> drinks;
            //string currentCategory = string.Empty;

            //if (string.IsNullOrEmpty(category))
            //{
            //    drinks = _drinkRepository.Drinks.OrderBy(p => p.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;
            //}

            //return View(new DrinksListViewModel
            //{
            //    Drinks = drinks,
            //    CurrentCategory = currentCategory
            //});
        }
示例#2
0
        public ViewResult List(string category)
        {
            DrinksListViewModel vm = new DrinksListViewModel();
            string _category       = category;
            IEnumerable <Drink> drinks;
            string currentCategory = string.Empty;

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

                currentCategory = _category;
            }

            return(View(new DrinksListViewModel
            {
                Drinks = drinks,
                CurrentCategory = currentCategory
            }));
        }
示例#3
0
        public IActionResult Index()
        {
            DrinksListViewModel DrinksList = GetList();

            if (DrinksList == null)
            {
                DrinksList        = new DrinksListViewModel();
                DrinksList.Drinks = new List <DrinkViewModel>();
            }
            return(View(DrinksList));
        }
示例#4
0
        public ViewResult List(string Category)
        {
            string _category = Category;
            IEnumerable <Drink> drinks;
            string currentCategory = string.Empty;

            if (string.IsNullOrEmpty(_category))
            {
                drinks = _drinkRepository.Drinks.OrderBy(x => x.Id);
            }
            else
            {
                drinks = _drinkRepository.Drinks.Where(x => x.Category.CategoryName == _category);
            }
            DrinksListViewModel vm = new DrinksListViewModel();

            vm.Drinks          = _drinkRepository.Drinks;
            vm.CurrentCategory = currentCategory;
            return(View(vm));
        }
        public ViewResult List(string category)
        {
            string _category = category;
            IEnumerable <Drink> drinks;
            string currentCategory = string.Empty;

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

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

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

            return(View(drinkListViewModel));
        }
示例#6
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 DrinksListViewModel
            {
                Drinks          = drinks,
                CurrentCategory = currentCategory
            };

            return(View(drinkListViewModel));
            //ViewBag.Name = "DotNet,How?";
            //DrinksListViewModel vm = new DrinksListViewModel();
            //vm.Drinks = _drinkRepository.Drinks;
            //vm.CurrentCategory = "DrinkCategory";
            //return View(vm);
        }
示例#7
0
 private void SaveList(DrinksListViewModel DrinksList)
 {
     HttpContext.Session.SetJson("DrinksList", DrinksList);
 }
示例#8
0
        private DrinksListViewModel GetList()
        {
            DrinksListViewModel DrinksList = HttpContext.Session.GetJson <DrinksListViewModel>("DrinksList");

            return(DrinksList);
        }