Ejemplo n.º 1
0
        public IActionResult Index(HamperIndexViewModel vm)
        {
            IQueryable <Hamper> hampers    = _hamperManager.GetAll().Include(h => h.Category);
            List <Category>     categories = _categoryManager.GetAll().ToList();

            categories.Insert(0, new Category {
                CategoryName = ""
            });
            if (!vm.IncludeInactive)
            {
                hampers = hampers.Where(h => h.Active);
            }
            if (vm.FilterCategoryName != null)
            {
                Category cat = _categoryManager.GetAll().Where(c => c.CategoryName == vm.FilterCategoryName).FirstOrDefault();
                hampers = hampers.Where(h => h.CategoryId == cat.CategoryId);
            }
            ;
            if (vm.FilterMinPrice > 0)
            {
                hampers = hampers.Where(h => h.HamperPrice >= vm.FilterMinPrice);
            }
            if (vm.FilterMaxPrice > 0)
            {
                hampers = hampers.Where(h => h.HamperPrice <= vm.FilterMaxPrice);
            }
            if (vm.FilterKeyword != null && vm.FilterKeyword != "")
            {
                hampers = hampers.Where(h => h.Category.CategoryName.Contains(vm.FilterKeyword) || h.HamperName.Contains(vm.FilterKeyword));
            }
            vm.Categories = categories;
            vm.Hampers    = hampers;
            return(View(vm));
        }
Ejemplo n.º 2
0
        public IActionResult Index()
        {
            double maxPrice = 0;
            double minPrice = 0;
            IEnumerable <Hamper>   activeHampers    = _hamperRepo.GetActiveHampers();
            IEnumerable <Category> activeCategories = _categoryRepo.Query(c => c.Active == true);


            if (activeHampers.Count() == 0)
            {
                return(RedirectToAction("Create"));
            }

            maxPrice = activeHampers.OrderByDescending(h => h.Price).ElementAt(0).Price;
            minPrice = activeHampers.OrderBy(h => h.Price).ElementAt(0).Price;


            HamperIndexViewModel vm = new HamperIndexViewModel();

            vm.Hampers    = activeHampers;
            vm.Categories = activeCategories;
            vm.MaxPrice   = maxPrice;
            vm.MinPrice   = minPrice;

            return(View(vm));
        }
        public async Task <IActionResult> RestoreIndex()
        {
            HamperIndexViewModel hamper = new HamperIndexViewModel();

            hamper.Hampers = _context.Hamper.Where(r => r.IsRemove == true).ToList();

            return(View(hamper));
        }
Ejemplo n.º 4
0
        public IActionResult GetInactiveHampers()
        {
            HamperIndexViewModel vm = new HamperIndexViewModel
            {
                Hampers = _hamperManager.GetAll().Where(h => !h.Active)
            };

            return(RedirectToAction("Index", vm));
        }
        public async Task <IActionResult> RestoreDetail(int?id, HamperIndexViewModel hamperViewModel)
        {
            var hamper = await _context.Hamper.SingleOrDefaultAsync(m => m.HamperId == id);

            hamper.IsRemove = hamperViewModel.IsRemove;
            await _context.SaveChangesAsync();


            return(RedirectToAction(nameof(Index)));
        }
        // GET: Hampers
        public async Task <IActionResult> Index(string searchInput, string searchCategory, int?MaxPrice, int?MinPrice)
        {
            HamperIndexViewModel hamper = new HamperIndexViewModel();

            hamper.Hampers = _context.Hamper.Where(r => r.IsRemove != true).ToList();

            IQueryable <string> categoriesList = _context.Category.OrderBy(n => n.CategoryName).Select(n => n.CategoryName);

            if (!String.IsNullOrEmpty(searchInput))
            {
                hamper.Hampers = _context.Hamper.Where(n => n.HamperName.Contains(searchInput)).ToList();
            }

            if (!String.IsNullOrEmpty(searchCategory))
            {
                var selectedCatogoryId = _context.Category.Where(n => n.CategoryName == searchCategory).Select(n => n.CategoryId).FirstOrDefault();
                hamper.Hampers = _context.Hamper.Where(n => n.CategoryId == selectedCatogoryId).ToList();
            }


            hamper.MinPrice = MinPrice.ToString();
            hamper.MaxPrice = MaxPrice.ToString();
            if (MaxPrice != null || MinPrice != null)
            {
                if (MaxPrice != null && MinPrice == null)
                {
                    hamper.Hampers = _context.Hamper.Where(p => p.HamperPrice <= MaxPrice).OrderBy(p => p.HamperPrice).ToList();
                }
                else if (MinPrice != null && MaxPrice == null)
                {
                    hamper.Hampers = _context.Hamper.Where(p => p.HamperPrice >= MinPrice).OrderBy(p => p.HamperPrice).ToList();
                }
                else
                {
                    hamper.Hampers = _context.Hamper.Where(p => p.HamperPrice <= MaxPrice && p.HamperPrice >= MinPrice).OrderBy(p => p.HamperPrice).ToList();
                }
            }


            hamper.CatogoryForSelect = new SelectList(await categoriesList.Distinct().ToListAsync());
            hamper.CategoryId        = hamper.Hampers.Select(i => i.CategoryId).ToList();
            hamper.DisplayHamper     = hamper.Hampers.ToList();

            hamper.Categories   = _context.Category.ToList();
            hamper.CategoryName = _context.Category.Select(i => i.CategoryName).ToList();

            return(View(hamper));
        }
Ejemplo n.º 7
0
        public IActionResult Index(HamperIndexViewModel vm)
        {
            string query    = vm.SearchQuery;
            double maxPrice = vm.MaxPrice;
            double minPrice = vm.MinPrice;
            string sortBy   = vm.SortBy;
            int    catId    = vm.CategoryId;

            IEnumerable <Hamper> searchResult = _hamperRepo.SearchHampers(query, catId, maxPrice, minPrice, sortBy);

            IEnumerable <Category> activeCategories = _categoryRepo.Query(c => c.Active == true);

            vm.Categories = activeCategories;
            vm.Hampers    = searchResult;

            return(View(vm));
        }
Ejemplo n.º 8
0
 public IActionResult Filter(HamperIndexViewModel vm)
 {
     return(RedirectToAction("Index", "Hamper", vm));
 }