public async Task <IActionResult> Programs(int page = 1, int?ageGroup = null) { var settings = await _performerSchedulingService.GetSettingsAsync(); var schedulingStage = _performerSchedulingService.GetSchedulingStage(settings); if (schedulingStage < PsSchedulingStage.SchedulingPreview) { return(RedirectToAction(nameof(Index))); } var filter = new PerformerSchedulingFilter(page, ProgramsPerPage) { AgeGroupId = ageGroup, IsApproved = true }; var programList = await _performerSchedulingService.GetPaginatedProgramListAsync(filter); var paginateModel = new PaginateViewModel { ItemCount = programList.Count, CurrentPage = page, ItemsPerPage = filter.Take.Value }; if (paginateModel.PastMaxPage) { return(RedirectToRoute( new { page = paginateModel.LastPage ?? 1 })); } var systemId = GetId(ClaimType.SystemId); foreach (var program in programList.Data) { program.AvailableInSystem = await _performerSchedulingService .GetPerformerSystemAvailabilityAsync(program.PerformerId, systemId); } var viewModel = new ProgramListViewModel { Programs = programList.Data, PaginateModel = paginateModel, AgeGroups = await _performerSchedulingService.GetAgeGroupsAsync(), AgeGroupId = ageGroup }; return(View(viewModel)); }