Esempio n. 1
0
        public async Task <IActionResult> Index()
        {
            var settings = await _performerSchedulingService.GetSettingsAsync();

            var schedulingStage = _performerSchedulingService.GetSchedulingStage(settings);

            if (schedulingStage == PsSchedulingStage.Unavailable)
            {
                ShowAlertDanger("Performer scheduling is not set up.");
                return(RedirectToAction(nameof(HomeController.Index), "Home"));
            }

            var systemId = GetId(ClaimType.SystemId);

            var viewModel = new ScheduleOverviewViewModel
            {
                Settings        = settings,
                SchedulingStage = schedulingStage,
                AgeGroups       = await _performerSchedulingService.GetAgeGroupsAsync(),
                CanSchedule     = UserHasPermission(Permission.SchedulePerformers)
            };

            if (schedulingStage >= PsSchedulingStage.SchedulingOpen)
            {
                var system = await _performerSchedulingService
                             .GetSystemWithoutExcludedBranchesAsync(systemId);

                viewModel.SystemName = system.Name;

                var branches = system.Branches;
                foreach (var branch in branches)
                {
                    branch.Selections = await _performerSchedulingService
                                        .GetSelectionsByBranchIdAsync(branch.Id);
                }

                viewModel.Branches = branches;
            }

            if (schedulingStage >= PsSchedulingStage.SchedulePosted)
            {
                var branches = await _performerSchedulingService
                               .GetNonExcludedSystemBranchesAsync(systemId, true);

                viewModel.BranchList = new SelectList(branches, "Id", "Name");
            }

            return(View(viewModel));
        }