Пример #1
0
        public async Task <IActionResult> Performers(int page = 1)
        {
            var settings = await _performerSchedulingService.GetSettingsAsync();

            var schedulingStage = _performerSchedulingService.GetSchedulingStage(settings);

            if (schedulingStage < PsSchedulingStage.SchedulingPreview)
            {
                return(RedirectToAction(nameof(Index)));
            }

            var filter = new PerformerSchedulingFilter(page, PerformersPerPage)
            {
                IsApproved = true
            };

            var performerList
                = await _performerSchedulingService.GetPaginatedPerformerListAsync(filter);

            var paginateModel = new PaginateViewModel
            {
                ItemCount    = performerList.Count,
                CurrentPage  = page,
                ItemsPerPage = filter.Take.Value
            };

            if (paginateModel.PastMaxPage)
            {
                return(RedirectToRoute(
                           new
                {
                    page = paginateModel.LastPage ?? 1
                }));
            }

            var systemId = GetId(ClaimType.SystemId);

            foreach (var performer in performerList.Data)
            {
                performer.AvailableInSystem = await _performerSchedulingService
                                              .GetPerformerSystemAvailabilityAsync(performer.Id, systemId);

                performer.ProgramCount = await _performerSchedulingService
                                         .GetPerformerProgramCountAsync(performer.Id);
            }

            var viewModel = new PerformerListViewModel
            {
                Performers    = performerList.Data,
                PaginateModel = paginateModel
            };

            return(View(viewModel));
        }