Exemplo n.º 1
0
        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));
        }
Exemplo n.º 2
0
        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"));
        }
Exemplo n.º 4
0
 public IEnumerable <Candy> GetAll()
 {
     return(_repo.GetAllCandy());
 }
Exemplo n.º 5
0
 public List <Candy> GetAllCandy()
 {
     return(_repo.GetAllCandy());
 }
Exemplo n.º 6
0
        public IEnumerable <Candy> GetAll()
        {
            var candies = _repo.GetAllCandy();

            return(candies);
        }