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));
        }
Esempio n. 2
0
        public async Task <JsonResult> GetProgramAvailableAgeGroups(int branchId, int programId)
        {
            PsProgram program;

            try
            {
                program = await _performerSchedulingService.GetProgramByIdAsync(programId,
                                                                                includeAgeGroups : true,
                                                                                onlyApproved : true);
            }
            catch (GraException gex)
            {
                return(Json(new
                {
                    success = false,
                    message = gex.Message
                }));
            }

            var settings = await _performerSchedulingService.GetSettingsAsync();

            var branchSelections = await _performerSchedulingService
                                   .GetSelectionsByBranchIdAsync(branchId);

            if (branchSelections.Count >= settings.SelectionsPerBranch)
            {
                return(Json(new
                {
                    success = false,
                    message = $"Branch has already made its {settings.SelectionsPerBranch} selections."
                }));
            }

            var availableAgeGroups = program.AgeGroups
                                     .Select(_ => _.Id.ToString())
                                     .Except(branchSelections.Select(_ => _.AgeGroupId.ToString()))
                                     .ToList();

            if (availableAgeGroups.Count == 0)
            {
                return(Json(new
                {
                    success = false,
                    message = "Branch already has selections for all of this programs age groups."
                }));
            }

            return(Json(new
            {
                success = true,
                data = availableAgeGroups
            }));
        }
Esempio n. 3
0
        public async Task <IActionResult> Program(int id, bool?list = null, int?ageGroup = null)
        {
            var settings = await _performerSchedulingService.GetSettingsAsync();

            var schedulingStage = _performerSchedulingService.GetSchedulingStage(settings);

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

            PsProgram program;

            try
            {
                program = await _performerSchedulingService.GetProgramByIdAsync(id,
                                                                                includeAgeGroups : true,
                                                                                includeImages : true,
                                                                                onlyApproved : true);
            }
            catch (GraException gex)
            {
                ShowAlertDanger("Unable to view program: ", gex);
                return(RedirectToAction(nameof(Programs)));
            }

            var selectedAgeGroup = program.AgeGroups.FirstOrDefault(_ => _.Id == ageGroup);

            var performer = await _performerSchedulingService.GetPerformerByIdAsync(
                program.PerformerId);

            var system = await _performerSchedulingService
                         .GetSystemWithoutExcludedBranchesAsync(GetId(ClaimType.SystemId));

            var viewModel = new ProgramViewModel
            {
                AgeGroup       = selectedAgeGroup,
                AllBranches    = performer.AllBranches,
                List           = list == true,
                Program        = program,
                SchedulingOpen = schedulingStage == PsSchedulingStage.SchedulingOpen,
                System         = system,
                CanSchedule    = UserHasPermission(Permission.SchedulePerformers)
            };

            if (!performer.AllBranches)
            {
                viewModel.BranchAvailability = await _performerSchedulingService
                                               .GetPerformerBranchIdsAsync(performer.Id, system.Id);
            }

            if (program.Images?.Count > 0)
            {
                viewModel.Image = _pathResolver.ResolveContentPath(
                    program.Images[0].Filename);
            }

            if (viewModel.SchedulingOpen)
            {
                viewModel.AgeGroupList = new SelectList(program.AgeGroups, "Id", "Name");
                var branches = new List <Branch>();
                foreach (var branch in system.Branches)
                {
                    if (!performer.AllBranches &&
                        !viewModel.BranchAvailability.Contains(branch.Id))
                    {
                        continue;
                    }
                    else
                    {
                        var branchSelections = await _performerSchedulingService
                                               .GetSelectionsByBranchIdAsync(branch.Id);

                        if (branchSelections.Count >= settings.SelectionsPerBranch)
                        {
                            continue;
                        }
                        else
                        {
                            var selectedAgeGroups  = branchSelections.Select(_ => _.AgeGroupId);
                            var availableAgeGroups = program.AgeGroups
                                                     .Any(_ => !selectedAgeGroups.Contains(_.Id));

                            if (!availableAgeGroups)
                            {
                                continue;
                            }
                        }
                    }
                    branches.Add(branch);
                }
                viewModel.BranchList = new SelectList(branches, "Id", "Name");
            }

            if (viewModel.List)
            {
                var programIndexList = await _performerSchedulingService.GetProgramIndexListAsync(
                    ageGroupId : selectedAgeGroup?.Id, onlyApproved : true);

                var index = programIndexList.IndexOf(id);
                viewModel.ReturnPage = (index / ProgramsPerPage) + 1;
                if (index != 0)
                {
                    viewModel.PrevProgram = programIndexList[index - 1];
                }
                if (programIndexList.Count != index + 1)
                {
                    viewModel.NextProgram = programIndexList[index + 1];
                }
            }

            return(View(viewModel));
        }