public IActionResult List(string category) { IEnumerable <Candy> candies; string currentCategory; if (string.IsNullOrEmpty(category)) { candies = _candyRepository.GetAllCandy().OrderBy(c => c.CandyId); currentCategory = "All Candy"; } else { candies = _candyRepository.GetAllCandy().Where(c => c.Category.CategoryName == category); currentCategory = _categoryRepository.GetAllCategories().FirstOrDefault(c => c.CategoryName == category)?.CategoryName; } var categoryView = new CandyListViewModel { Candies = candies, CurrentCategory = currentCategory }; return(View(categoryView)); }
public IActionResult List(string category) { //ViewBag.CurrentCategory = "Bestsellers"; //return View(_candyRepository.GetAllCandy); // var candyListViewModel = new CandyListViewModel(); // candyListViewModel.Candies = _candyRepository.GetAllCandy(); // candyListViewModel.CurrentCategory = "Bestsellers"; // return View(candyListViewModel); IEnumerable <Candy> candies; string currentCategory; if (string.IsNullOrEmpty(category)) { candies = _candyRepository.GetAllCandy().OrderBy(c => c.CandyId); currentCategory = "All Candy"; } else { candies = _candyRepository.GetAllCandy().Where(c => c.Category.CategoryName == category); currentCategory = _categoryRepository.GetAllCategories().FirstOrDefault(c => c.CategoryName == category)?.CategoryName; } return(View(new CandyListViewModel { Candies = candies, CurrentCategory = currentCategory })); }
public RedirectToActionResult AddCandyToCart(int candyId) { var selectedCandy = _candyRepository.GetAllCandy().FirstOrDefault(c => c.CandyId == candyId); if (selectedCandy != null) { _shoppingCart.AddToCart(selectedCandy, 1); } return(RedirectToAction("Index")); }
public IEnumerable <Candy> GetAll() { return(_repo.GetAllCandy()); }
public List <Candy> GetAllCandy() { return(_repo.GetAllCandy()); }
public IEnumerable <Candy> GetAll() { var candies = _repo.GetAllCandy(); return(candies); }