Ejemplo n.º 1
0
        public async Task <JsonResult> GetKitAvailableAgeGroups(int branchId, int kitId)
        {
            PsKit kit;

            try
            {
                kit = await _performerSchedulingService.GetKitByIdAsync(kitId,
                                                                        includeAgeGroups : 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 = kit.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 kits age groups."
                }));
            }

            return(Json(new
            {
                success = true,
                data = availableAgeGroups
            }));
        }
Ejemplo n.º 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));
        }