示例#1
0
        public IActionResult List(string categoryName)
        {
            try{
                IEnumerable <Snack> snacks;

                if (string.IsNullOrEmpty(categoryName))
                {
                    snacks       = _snackRepository.FindAll();
                    categoryName = "Todos os lanches";
                }
                else
                {
                    snacks = _snackRepository.SnackByCategory(categoryName);
                }

                var snackListViewModel = new SnackListViewModel();
                snackListViewModel.Snacks   = snacks;
                snackListViewModel.Category = categoryName;
                return(View(snackListViewModel));
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                return(RedirectToAction("Index"));
            }
        }