示例#1
0
        public async Task <ActionResult> Edit(int?groupUId, int?establishmentUrn, int?removalGid, int?duplicateGovernorId, bool roleAlreadyExists = false)
        {
            Guard.IsTrue(groupUId.HasValue || establishmentUrn.HasValue, () => new InvalidParameterException($"Both parameters '{nameof(groupUId)}' and '{nameof(establishmentUrn)}' are null."));

            var domainModel = await _governorsReadService.GetGovernorListAsync(establishmentUrn, groupUId, User);

            var governorPermissions = await _governorsReadService.GetGovernorPermissions(establishmentUrn, groupUId, User);

            var viewModel = new GovernorsGridViewModel(domainModel,
                                                       true,
                                                       groupUId,
                                                       establishmentUrn,
                                                       _nomenclatureService,
                                                       await _cachedLookupService.NationalitiesGetAllAsync(),
                                                       await _cachedLookupService.GovernorAppointingBodiesGetAllAsync(),
                                                       governorPermissions);

            var applicableRoles = domainModel.ApplicableRoles.Cast <int>();

            viewModel.GovernorRoles = (await _cachedLookupService.GovernorRolesGetAllAsync()).Where(x => applicableRoles.Contains(x.Id)).Select(x => new LookupItemViewModel(x)).ToList();

            await _layoutHelper.PopulateLayoutProperties(viewModel, establishmentUrn, groupUId, User, x => viewModel.GovernanceMode = x.GovernanceMode, x =>
            {
                viewModel.ShowDelegationAndCorpContactInformation = x.GroupTypeId.GetValueOrDefault() == (int)eLookupGroupType.MultiacademyTrust;
                viewModel.DelegationInformation = x.DelegationInformation;
                viewModel.CorporateContact      = x.CorporateContact;
            });

            viewModel.RemovalGid     = removalGid;
            viewModel.GovernorShared = false;
            if (removalGid.HasValue)
            {
                var govToBeRemoved = domainModel.CurrentGovernors.SingleOrDefault(g => g.Id == removalGid.Value);
                if (govToBeRemoved != null && EnumSets.SharedGovernorRoles.Contains(govToBeRemoved.RoleId.Value))
                {
                    viewModel.GovernorShared = true;
                }
            }

            if (duplicateGovernorId.HasValue)
            {
                var duplicate = await _governorsReadService.GetGovernorAsync(duplicateGovernorId.Value, User);

                ViewData.Add("DuplicateGovernor", duplicate);
            }

            if (roleAlreadyExists)
            {
                ModelState.AddModelError("role", "The selected role already contains an appointee.");
            }

            return(View(VIEW_EDIT_GOV_VIEW_NAME, viewModel));
        }
        private async Task <ActionResult> SearchGovernors(GovernorSearchViewModel model)
        {
            if (model.GovernorSearchModel?.RoleId != null && model.GovernorSearchModel.RoleId.Any())
            {
                model.SelectedRoleIds.AddRange(model.GovernorSearchModel.RoleId
                                               .Where(r => !model.SelectedRoleIds.Contains(r))
                                               .Cast <int>());
            }

            model.SearchQueryString = Request.QueryString.ToString();
            model.GovernorRoles     = (await _cachedLookupService.GovernorRolesGetAllAsync()).Select(x => new LookupItemViewModel(x)).ToList();
            model.AppointingBodies  = (await _cachedLookupService.GovernorAppointingBodiesGetAllAsync()).Select(x => new LookupItemViewModel(x)).ToList();
            model.LocalAuthorities  = (await _cachedLookupService.LocalAuthorityGetAllAsync()).Select(x => new LookupItemViewModel(x)).ToList();

            var payload = CreateSearchPayload(model);
            var results = await _governorsReadService.SearchAsync(payload, User);

            model.Results = results.Items;

            if (model.StartIndex == 0)
            {
                model.Count = results.Count;
            }

            return(View("Index", model));
        }
        public static async Task <SharedGovernorViewModel> MapFromGovernor(GovernorModel governor, int establishmentUrn, ICachedLookupService cachedLookupService)
        {
            var dateNow     = DateTime.Now.Date;
            var appointment = governor.Appointments?.SingleOrDefault(g => g.EstablishmentUrn == establishmentUrn);
            var sharedWith  = governor.Appointments?
                              .Where(a => a.AppointmentStartDate < dateNow && (a.AppointmentEndDate == null || a.AppointmentEndDate > dateNow))
                              .Select(a => new EstablishmentViewModel {
                Urn = a.EstablishmentUrn.Value, EstablishmentName = a.EstablishmentName
            })
                              .ToList();

            var appointingBodies = await cachedLookupService.GovernorAppointingBodiesGetAllAsync();

            var nationalities = await cachedLookupService.NationalitiesGetAllAsync();

            return(new SharedGovernorViewModel
            {
                AppointingBodyName = appointingBodies.Single(g => g.Id == governor.AppointingBodyId).Name,
                AppointmentStartDate = appointment?.AppointmentStartDate != null ? new DateTimeViewModel(appointment.AppointmentStartDate) : new DateTimeViewModel(),
                AppointmentEndDate = appointment?.AppointmentEndDate != null ? new DateTimeViewModel(appointment.AppointmentEndDate) : new DateTimeViewModel(),
                DOB = governor.DOB,
                FullName = governor.GetFullName(),
                Id = governor.Id.Value,
                PostCode = governor.PostCode,
                Selected = appointment != null,
                PreExisting = appointment != null,
                SharedWith = sharedWith ?? new List <EstablishmentViewModel>(),
                MultiSelect = IsSharedGovernorRoleMultiSelect((eLookupGovernorRole)governor.RoleId)
            });
        }
示例#4
0
        private async Task <ActionResult> SearchGovernors(GovernorSearchViewModel model)
        {
            // before processing any of the model, make sure something has been searched for if not 'All'
            if ((model.SearchType == eSearchType.Governor &&
                 model.SelectedRoleIds.Count == 0 &&
                 model.GovernorSearchModel.Forename.IsNullOrEmpty() &&
                 model.GovernorSearchModel.Surname.IsNullOrEmpty()) ||
                (model.SearchType == eSearchType.GovernorReference &&
                 !model.GovernorSearchModel.Gid.HasValue))
            {
                return(RedirectToSearchPage(model));
            }

            if (model.GovernorSearchModel?.RoleId != null && model.GovernorSearchModel.RoleId.Any())
            {
                model.SelectedRoleIds.AddRange(model.GovernorSearchModel.RoleId
                                               .Where(r => !model.SelectedRoleIds.Contains(r))
                                               .Cast <int>());
            }

            model.SearchQueryString = Request.QueryString.ToString();
            model.GovernorRoles     = (await _cachedLookupService.GovernorRolesGetAllAsync()).Select(x => new LookupItemViewModel(x)).ToList();
            model.AppointingBodies  = (await _cachedLookupService.GovernorAppointingBodiesGetAllAsync()).Select(x => new LookupItemViewModel(x)).ToList();
            model.LocalAuthorities  = (await _cachedLookupService.LocalAuthorityGetAllAsync()).Select(x => new LookupItemViewModel(x)).ToList();

            var payload = CreateSearchPayload(model);
            var results = await _governorsReadService.SearchAsync(payload, User);

            model.Results = results.Items;

            if (model.StartIndex == 0)
            {
                model.Count = results.Count;
            }
            if (model.Count == 0)
            {
                return(RedirectToSearchPage(model));
            }

            return(View("Index", model));
        }