Esempio n. 1
0
        public IActionResult Index(int?page, int?popPage, string occasion, string who, string category, string sliderPrice)
        {
            IndexViewModel viewModel = new IndexViewModel();

            viewModel.DistinctOccasion = _tagService.GetAllDistinctValues(1);
            viewModel.DistinctCategory = _tagService.GetAllDistinctValues(2);
            viewModel.DistinctWho      = _tagService.GetAllDistinctValues(3);
            int pageNo    = SetPageViewData(page, ViewData, null);
            int popPageNo = SetPageViewData(popPage, ViewData, "Popular");

            ViewData["url"] = Request.Path;

            if (sliderPrice != null)
            {
                viewModel.PresentsResults = _giftService.FindGifts(pageNo, sliderPrice, category, who, occasion);
                viewModel.HeadLine        = "Gaver som matcher din søgning";
                if (viewModel.PresentsResults == null)
                {
                    viewModel.HeadLine        = "Den valgte parameterkombination er ugyldig";
                    viewModel.PresentsResults = new List <Present>();
                }
                else if (viewModel.PresentsResults.Count == 0)
                {
                    viewModel.HeadLine = "Ingen gaver matcher søgningen";
                }
            }
            else
            {
                viewModel.PresentsResults = _giftService.ListRandomGifts(pageNo);
            }
            viewModel.PresentResultsLimit = viewModel.PresentsResults.Skip((pageNo - 1) * 9).Take(9).ToList();
            viewModel.HasNextPage         = HasNextPage(pageNo, viewModel.PresentsResults.Count, 9d);
            viewModel.HasPrevPage         = HasPrevPage(pageNo);

            viewModel.PopularPresents = _giftService.ListPopularGifts(popPageNo);
            viewModel.PopHasNextPage  = HasNextPage(popPageNo, _db.Present.Count(), 3d);
            viewModel.PopHasPrevPage  = HasPrevPage(popPageNo);

            return(View(viewModel));
        }