예제 #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
            }));
        }
예제 #2
0
        public async Task <IActionResult> Kit(int id)
        {
            var settings = await _performerSchedulingService.GetSettingsAsync();

            var schedulingStage = _performerSchedulingService.GetSchedulingStage(settings);

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

            PsKit kit;

            try
            {
                kit = await _performerSchedulingService.GetKitByIdAsync(id, includeAgeGroups : true,
                                                                        includeImages : true);
            }
            catch (GraException gex)
            {
                ShowAlertDanger("Unable to view kit: ", gex);
                return(RedirectToAction(nameof(Kits)));
            }

            var viewModel = new KitViewModel
            {
                Kit            = kit,
                SchedulingOpen = schedulingStage == PsSchedulingStage.SchedulingOpen,
                CanSchedule    = UserHasPermission(Permission.SchedulePerformers)
            };

            if (kit.Images.Count > 0)
            {
                viewModel.ImagePath = _pathResolver.ResolveContentPath(
                    kit.Images[0].Filename);
            }

            if (!string.IsNullOrWhiteSpace(kit.Website) &&
                Uri.TryCreate(kit.Website, UriKind.Absolute, out Uri absoluteUri))
            {
                viewModel.Uri = absoluteUri;
            }

            if (viewModel.SchedulingOpen)
            {
                viewModel.AgeGroupList = new SelectList(kit.AgeGroups, "Id", "Name");

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

                var branches = new List <Branch>();
                foreach (var branch in system.Branches)
                {
                    var branchSelections = await _performerSchedulingService
                                           .GetSelectionsByBranchIdAsync(branch.Id);

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

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

            var kitIndexList = await _performerSchedulingService.GetKitIndexListAsync();

            var index = kitIndexList.IndexOf(id);

            viewModel.ReturnPage = (index / KitsPerPage) + 1;
            if (index != 0)
            {
                viewModel.PrevKit = kitIndexList[index - 1];
            }
            if (kitIndexList.Count != index + 1)
            {
                viewModel.NextKit = kitIndexList[index + 1];
            }

            return(View(viewModel));
        }