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 async Task <ActionResult> Index(SearchViewModel viewModel) { if (!viewModel.NoResultsForLocation && !viewModel.NoResultsForName && !viewModel.NoResultsForLA) { if (viewModel.LocalAuthorityToRemove.HasValue) { return(Redirect("/?" + QueryStringHelper.ToQueryString(SearchViewModel.BIND_ALIAS_LAIDS, viewModel.RemoveLocalAuthorityId(viewModel.LocalAuthorityToRemove.Value).SelectedLocalAuthorityIds.ToArray()) + "#la")); } if (viewModel.SearchType.HasValue) { if (viewModel.SearchType == eSearchType.LocalAuthorityDisambiguation) { return(await ProcessLocalAuthorityDisambiguation(viewModel)); } if (ModelState.IsValid) { if (viewModel.SearchType == eSearchType.Location && LatLon.Parse(viewModel.LocationSearchModel.AutoSuggestValue) == null && !viewModel.LocationSearchModel.Text.IsNullOrEmpty()) { return(await ProcessLocationDisambiguation(viewModel)); } } } } viewModel.LocalAuthorities = (await _cachedLookupService.LocalAuthorityGetAllAsync()).OrderBy(x => x.Name).Select(x => new LookupItemViewModel(x)); viewModel.GovernorRoles = (await _cachedLookupService.GovernorRolesGetAllAsync()).OrderBy(x => x.Name).Select(x => new LookupItemViewModel(x)); return(View("Index", viewModel)); }
public async Task <ActionResult> SelectSharedGovernor(int establishmentUrn, eLookupGovernorRole role) { var roleName = (await _cachedLookupService.GovernorRolesGetAllAsync()).Single(x => x.Id == (int)role).Name; var governors = (await _governorsReadService.GetSharedGovernorsAsync(establishmentUrn, User)).Where(g => RoleEquivalence.GetEquivalentRole(role).Contains((eLookupGovernorRole)g.RoleId)).ToList(); var sharedGovernors = governors.Select(async g => await SharedGovernorViewModel.MapFromGovernor(g, establishmentUrn, _cachedLookupService)); var viewModel = new SelectSharedGovernorViewModel { Governors = (await Task.WhenAll(sharedGovernors)).ToList(), GovernorType = roleName.ToLowerInvariant(), }; await _layoutHelper.PopulateLayoutProperties(viewModel, establishmentUrn, null, User); return(View(viewModel)); }
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 <EstablishmentSearchViewModel> PopulateLookups(EstablishmentSearchViewModel vm) { vm.LocalAuthorities = (await _lookupService.LocalAuthorityGetAllAsync()).OrderBy(x => x.Name) .Select(x => new LookupItemViewModel(x)); vm.GovernorRoles = (await _lookupService.GovernorRolesGetAllAsync()).OrderBy(x => x.Name) .Select(x => new LookupItemViewModel(x)); vm.AdmissionsPolicies = (await _lookupService.AdmissionsPoliciesGetAllAsync()).OrderBy(x => x.Name) .Select(x => new LookupItemViewModel(x)); vm.BoardingProvisions = (await _lookupService.ProvisionBoardingGetAllAsync()).OrderBy(x => x.Name) .Select(x => new LookupItemViewModel(x)); vm.Dioceses = (await _lookupService.DiocesesGetAllAsync()).OrderBy(x => x.Name) .Select(x => new LookupItemViewModel(x)); vm.Districts = (await _lookupService.AdministrativeDistrictsGetAllAsync()).OrderBy(x => x.Name) .Select(x => new LookupItemViewModel(x)); vm.FurtherEducationTypes = (await _lookupService.FurtherEducationTypesGetAllAsync()) .OrderBy(x => x.Name) .Select(x => new LookupItemViewModel(x)); vm.Genders = (await _lookupService.GendersGetAllAsync()).OrderBy(x => x.Name) .Select(x => new LookupItemViewModel(x)); vm.GORs = (await _lookupService.GovernmentOfficeRegionsGetAllAsync()).OrderBy(x => x.Name) .Select(x => new LookupItemViewModel(x)); vm.NurseryProvisions = (await _lookupService.ProvisionNurseriesGetAllAsync()).OrderBy(x => x.Name) .Select(x => new LookupItemViewModel(x)); vm.ParliamentaryConstituencies = (await _lookupService.ParliamentaryConstituenciesGetAllAsync()) .OrderBy(x => x.Name) .Select(x => new LookupItemViewModel(x)); vm.ReligiousEthoses = (await _lookupService.ReligiousEthosGetAllAsync()).OrderBy(x => x.Name) .Select(x => new LookupItemViewModel(x)); vm.RSCRegions = (await _lookupService.RscRegionsGetAllAsync()).OrderBy(x => x.Name) .Select(x => new LookupItemViewModel(x)); vm.Section41Designations = (await _lookupService.Section41ApprovedGetAllAsync()).OrderBy(x => x.Name) .Select(x => new LookupItemViewModel(x)); vm.SixthFormProvisions = (await _lookupService.ProvisionOfficialSixthFormsGetAllAsync()) .OrderBy(x => x.Name) .Select(x => new LookupItemViewModel(x)); vm.SpecialClassesProvisions = (await _lookupService.ProvisionSpecialClassesGetAllAsync()) .OrderBy(x => x.Name) .Select(x => new LookupItemViewModel(x)); vm.TypeOfSENProvisions = (await _lookupService.SpecialEducationNeedsGetAllAsync()).OrderBy(x => x.Name) .Select(x => new LookupItemViewModel(x)); vm.UrbanRuralDesignations = (await _lookupService.UrbanRuralGetAllAsync()).OrderBy(x => x.Name) .Select(x => new LookupItemViewModel(x)); vm.OfstedRatings = (await _lookupService.OfstedRatingsGetAllAsync()).OrderBy(x => x.Name) .Select(x => new LookupItemViewModel(x)); return(vm); }
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)); }
public async Task <ActionResult> Index(SearchViewModel viewModel) { if (!viewModel.NoResults) { if (viewModel.LocalAuthorityToRemove.HasValue) { return(Redirect("/?" + QueryStringHelper.ToQueryString(SearchViewModel.BIND_ALIAS_LAIDS, viewModel.RemoveLocalAuthorityId(viewModel.LocalAuthorityToRemove.Value).SelectedLocalAuthorityIds.ToArray()) + "#la")); } if (viewModel.SearchType.HasValue) { if (viewModel.SearchType == eSearchType.LocalAuthorityDisambiguation) { return(await ProcessLocalAuthorityDisambiguation(viewModel)); } if (ModelState.IsValid) { if (viewModel.SearchType == eSearchType.Location && LatLon.Parse(viewModel.LocationSearchModel.AutoSuggestValue) == null && !viewModel.LocationSearchModel.Text.IsNullOrEmpty()) { var disambiguationResult = await ProcessLocationDisambiguation(viewModel.LocationSearchModel.Text); if (disambiguationResult != null) { return(disambiguationResult); } } } else if (viewModel.SearchType == eSearchType.GovernorReference) { var fieldError = viewModel.GovernorSearchModel.Gid.HasValue ? "We could not find any governors matching your search criteria" : "Please enter a governor ID to start a search"; viewModel.ErrorPanel = "GovernorId"; ModelState.AddModelError("GovernorSearchModel.Gid", fieldError); } } } else { var fieldId = "TextSearchModel.Text"; var fieldError = "We could not find any establishments matching your search criteria"; var la = Request.QueryString["LocalAuthorityToAdd"]; switch (viewModel.SearchType) { case eSearchType.Text: if (viewModel.TextSearchModel.Text.IsNullOrEmpty()) { fieldError = "Please enter an establishment name, URN, LAESTAB or UKPRN to start a search"; } viewModel.ErrorPanel = "Name"; break; case eSearchType.Location: fieldId = "LocationSearchModel.Text"; fieldError = "Please enter a postcode, town or city to start a search"; viewModel.ErrorPanel = "Location"; break; case eSearchType.ByLocalAuthority: if (!string.IsNullOrEmpty(viewModel.LocalAuthorityToAdd)) { return(await ProcessLocalAuthorityDisambiguation(viewModel)); } fieldId = "LocalAuthorityToAdd"; fieldError = viewModel.SelectedLocalAuthorityIds.Any() ? "We could not find any local authorities matching your search criteria" : "Please enter a local authority to start a search"; viewModel.ErrorPanel = "LocalAuthority"; break; case eSearchType.Group: fieldId = "GroupSearchModel.Text"; fieldError = viewModel.GroupSearchModel.Text.IsNullOrEmpty() ? "Please enter an establishment group to start a search" : "We could not find any establishment groups matching your search criteria"; viewModel.ErrorPanel = "Group"; break; case eSearchType.Governor: fieldId = "GovernorSearchModel.Forename"; fieldError = viewModel.GovernorSearchModel.Forename.IsNullOrEmpty() && viewModel.GovernorSearchModel.Surname.IsNullOrEmpty() && viewModel.GovernorSearchModel.RoleId.Length == 0 ? "Please enter a governor to start a search" : "We could not find any governors matching your search criteria"; viewModel.ErrorPanel = "Governor"; break; case eSearchType.GovernorReference: fieldId = "GovernorSearchModel.Gid"; fieldError = viewModel.GovernorSearchModel.Gid.HasValue ? "We could not find any governors matching your search criteria" : "Please enter a governor ID to start a search"; viewModel.ErrorPanel = "GovernorId"; break; } ModelState.AddModelError(fieldId, fieldError); } viewModel.LocalAuthorities = (await _cachedLookupService.LocalAuthorityGetAllAsync()).OrderBy(x => x.Name).Select(x => new LookupItemViewModel(x)); viewModel.GovernorRoles = (await _cachedLookupService.GovernorRolesGetAllAsync()).OrderBy(x => x.Name).Select(x => new LookupItemViewModel(x)); return(View("Index", viewModel)); }