public async Task <IActionResult> Program(int?id = null)
        {
            var settings = await _performerSchedulingService.GetSettingsAsync();

            var schedulingStage = _performerSchedulingService.GetSchedulingStage(settings);

            if (schedulingStage != PsSchedulingStage.RegistrationOpen)
            {
                return(RedirectToAction(nameof(Index)));
            }

            var userId    = GetId(ClaimType.UserId);
            var performer = await _performerSchedulingService.GetPerformerByUserIdAsync(userId);

            if (performer == null)
            {
                return(RedirectToAction(nameof(Information)));
            }
            else if (!performer.SetSchedule)
            {
                return(RedirectToAction(nameof(Schedule)));
            }

            var ageGroups = await _performerSchedulingService.GetAgeGroupsAsync();

            var ageList = new SelectList(ageGroups, "Id", "Name");

            if (ageList.Count() == 1)
            {
                ageList.First().Selected = true;
            }

            var viewModel = new ProgramViewModel
            {
                AgeList               = ageList,
                MaxUploadMB           = MaxUploadMB,
                RegistrationCompleted = performer.RegistrationCompleted,
                SetupSupplementalText = settings.SetupSupplementalText
            };

            if (id.HasValue)
            {
                try
                {
                    var program = await _performerSchedulingService.GetProgramByIdAsync(id.Value,
                                                                                        includeAgeGroups : true);

                    viewModel.AgeSelection   = program.AgeGroups.Select(_ => _.Id).ToList();
                    viewModel.EditingProgram = true;
                    viewModel.Program        = program;
                }
                catch (GraException gex)
                {
                    ShowAlertDanger("Unable to view Program: ", gex);
                    return(RedirectToAction(nameof(Dashboard)));
                }
            }

            return(View(viewModel));
        }
Exemple #2
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));
        }