Ejemplo n.º 1
0
        public async Task <IActionResult> IndexWithCategory(string category, [FromQuery] int page, [FromQuery] int pageSize)
        {
            var categories = await _stockportApiEventsService.GetEventCategories();

            var viewModel = new EventResultsVIewModel()
            {
                Title = category
            };

            var events = await _stockportApiEventsService.GetEventsByCategory(category, false);

            if (events == null || !events.Any())
            {
                return(View("Index", viewModel));
            }

            var eventCategory = categories.FirstOrDefault(c => c.Slug == category);

            viewModel.Title  = eventCategory != null ? eventCategory.Name : category;
            viewModel.Events = events;

            viewModel.AddQueryUrl(new QueryUrl(Url?.ActionContext.RouteData.Values, Request?.Query));
            _filteredUrl.SetQueryUrl(viewModel.CurrentUrl);
            viewModel.AddFilteredUrl(_filteredUrl);

            DoPagination(viewModel, page, pageSize);

            return(View("Index", viewModel));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> Index()
        {
            var homepage = await _homepageService.GetHomepage();

            if (homepage == null)
            {
                return(new NotFoundResult());
            }

            var eventsFromApi = !string.IsNullOrEmpty(homepage.EventCategory) ? await _stockportApiEventsService.GetEventsByCategory(homepage.EventCategory) : new List <Event>();

            var homepageViewModel = new HomepageViewModel
            {
                HomepageContent = homepage,
                FeaturedEvent   = _businessId.ToString() != "healthystockport" ? await _eventsService.GetLatestFeaturedEventItem() : null,
                FeaturedNews    = _businessId.ToString() != "healthystockport" ? await _newsService.GetLatestNewsItem() : null,
                EventsFromApi   = eventsFromApi?.Take(3).ToList()
            };

            return(View(homepageViewModel));
        }