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> JsonResults(EstablishmentSearchViewModel model) { var payload = await GetEstablishmentSearchPayload(model); payload.Object.Take = 100; if (!payload.Success) { model.Error = payload.ErrorMessage; } await ProcessEstablishmentsSearch(model, payload.Object); var localAuthorities = (await _lookupService.LocalAuthorityGetAllAsync()); var establishmentTypes = await _lookupService.EstablishmentTypesGetAllAsync(); var educationPhases = await _lookupService.EducationPhasesGetAllAsync(); var counties = (await _lookupService.CountiesGetAllAsync()).Where(c => c.Id != 63); //remove "not recorded" HttpContext.Response.Headers.Add("x-count", model.Count.ToString()); var filtered = model.Results .Select(result => new { Result = result, LA = localAuthorities.SingleOrDefault(la => la.Id == result.LocalAuthorityId) }) .Select(a => new { Name = a.Result.Name, Location = a.Result.Location, Address = StringUtil.ConcatNonEmpties(", ", a.Result.Address_Line1, a.Result.Address_Locality, a.Result.Address_Line3, a.Result.Address_CityOrTown, counties.FirstOrDefault(c => c.Id == a.Result.Address_CountyId)?.Name, a.Result.Address_PostCode), Urn = a.Result.Urn, LAESTAB = a.LA?.Code != null && a.Result.EstablishmentNumber.HasValue ? $"{a.LA.Code}/{a.Result.EstablishmentNumber.Value:D4}" : string.Empty, Status = model.EstablishmentStatuses.FirstOrDefault(x => x.Id == a.Result.StatusId)?.Name ?? "Not recorded", LocalAuthority = a.LA?.Name ?? "Not recorded", PhaseType = string.Concat( educationPhases.FirstOrDefault(x => x.Id == a.Result.EducationPhaseId)?.Name ?? "Not recorded", ", ", establishmentTypes.FirstOrDefault(x => x.Id == a.Result.TypeId)?.Name ?? "Not recorded"), }); return(Json(filtered)); }
private async Task <GroupEditorViewModel> PopulateSelectLists(GroupEditorViewModel viewModel) { viewModel.LocalAuthorities = (await _lookup.LocalAuthorityGetAllAsync()).ToSelectList(viewModel.LocalAuthorityId); viewModel.CCGroupTypes = (await _lookup.GroupTypesGetAllAsync()) .Where(x => x.Id.OneOfThese(GT.ChildrensCentresCollaboration, GT.ChildrensCentresGroup)).OrderBy(x => x.Id).ToSelectList(viewModel.GroupTypeId); return(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 async Task <ActionResult> MergersTool() { var settings = new JsonSerializerSettings { ContractResolver = new CamelCasePropertyNamesContractResolver() }; var type2PhaseMap = _establishmentReadService.GetEstabType2EducationPhaseMap().AsInts(); var type2PhaseMapJson = JsonConvert.SerializeObject(type2PhaseMap, Formatting.None, settings); var las = (await _lookup.LocalAuthorityGetAllAsync()).Select(x => new { x.Id, x.Name }); var lasJson = JsonConvert.SerializeObject(las, Formatting.None, settings); var phases = (await _lookup.EducationPhasesGetAllAsync()).Select(x => new { x.Id, x.Name }); var phasesJson = JsonConvert.SerializeObject(phases, Formatting.None, settings); var types = (await _lookup.EstablishmentTypesGetAllAsync()).Select(x => new { x.Id, x.Name }); var typesJson = JsonConvert.SerializeObject(types, Formatting.None, settings); ViewBag.Type2PhaseMapJson = type2PhaseMapJson; ViewBag.LocalAuthoritiesJson = lasJson; ViewBag.TypesJson = typesJson; ViewBag.PhasesJson = phasesJson; return(View()); }
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)); }
private async Task <Tuple <int, string> > TryGetEstablishment(ChangeHistoryViewModel viewModel) { if (viewModel.TextSearchType == ChangeHistoryViewModel.eTextSearchType.URN) { var urn = Int32.Parse(viewModel.TextSearchModel.Text); var establishmentName = (await _establishmentReadService.GetEstablishmentNameAsync(urn, User)) ?? ""; return(new Tuple <int, string>(urn, establishmentName)); } else { int? urn = null; string name = null; if (viewModel.TextSearchModel.AutoSuggestValueAsInt.HasValue) { urn = viewModel.TextSearchModel.AutoSuggestValueAsInt; name = (await _establishmentReadService.GetEstablishmentNameAsync(urn.Value, User)) ?? ""; } else { var payload = new EstablishmentSearchPayload(viewModel.Skip, viewModel.Take); var filters = payload.Filters; if (viewModel.SearchType == eSearchType.Text || viewModel.SearchType == eSearchType.EstablishmentAll) { if (viewModel.TextSearchType == ChangeHistoryViewModel.eTextSearchType.UKPRN) { filters.UKPRN = viewModel.TextSearchModel.Text; } else if (viewModel.TextSearchType == ChangeHistoryViewModel.eTextSearchType.LAESTAB) { var laestab = LAESTAB.TryParse(viewModel.TextSearchModel.Text).Value; var localAuthorityId = (await _lookupService.LocalAuthorityGetAllAsync()).FirstOrDefault(x => x.Code == laestab.LocalAuthorityCode)?.Id; if (localAuthorityId.HasValue) { filters.LocalAuthorityIds = new int[] { localAuthorityId.Value } } ; filters.EstablishmentNumber = laestab.EstablishmentNumber; } else if (viewModel.TextSearchType == ChangeHistoryViewModel.eTextSearchType.EstablishmentName) { payload.Text = viewModel.TextSearchModel.Text; } else { return(null); } } var results = await _establishmentReadService.SearchAsync(payload, User); if (results != null && results.Items.Any()) { urn = results.Items.First().Urn; name = results.Items.First().Name; } } if (urn.HasValue) { return(new Tuple <int, string>(urn.Value, name)); } } return(null); }
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)); }
public async Task <ActionResult> ProcessAmalgamationEstablishmentsAsync(AmalgamateEstablishmentsModel model) { var viewModel = new AmalgamateEstablishmentsModel(); var submittedUrns = new List <int>(); var estab0HasErrors = ModelState.Keys.Where(k => k == "Establishment0Urn") .Select(k => ModelState[k].Errors).First().Select(e => e.ErrorMessage).Any(); var estab1HasErrors = ModelState.Keys.Where(k => k == "Establishment1Urn") .Select(k => ModelState[k].Errors).First().Select(e => e.ErrorMessage).Any(); if (!model.Establishment0Urn.HasValue && !estab0HasErrors) { ModelState.AddModelError(nameof(model.Establishment0Urn), "Enter the establishment 1 URN"); } if (!model.Establishment1Urn.HasValue && !model.Establishment2Urn.HasValue && !model.Establishment3Urn.HasValue) { if (!estab1HasErrors) { ModelState.AddModelError(nameof(model.Establishment1Urn), "Enter the establishment 2 URN"); } } if (model.Establishment0Urn.HasValue) { var estab = await _establishmentReadService.GetAsync(model.Establishment0Urn.GetValueOrDefault(), User); if (estab.GetResult() == null && !estab1HasErrors) { ViewData.ModelState.AddModelError(nameof(model.Establishment0Urn), "The establishment 1 URN is invalid"); } else { viewModel.Establishment0Urn = model.Establishment0Urn; viewModel.Establishment0Name = estab.GetResult().Name; submittedUrns.Add(model.Establishment0Urn.GetValueOrDefault()); } } if (model.Establishment1Urn.HasValue) { var estab1 = await _establishmentReadService.GetAsync(model.Establishment1Urn.GetValueOrDefault(), User); if (estab1.GetResult() == null) { ViewData.ModelState.AddModelError(nameof(model.Establishment1Urn), "The establishment 1 URN is invalid"); } else { viewModel.Establishment1Urn = model.Establishment1Urn; viewModel.Establishment1Name = estab1.GetResult().Name; submittedUrns.Add(model.Establishment1Urn.GetValueOrDefault()); } } if (model.Establishment2Urn.HasValue) { var estab2 = await _establishmentReadService.GetAsync(model.Establishment2Urn.GetValueOrDefault(), User); if (estab2.GetResult() == null) { ViewData.ModelState.AddModelError(nameof(model.Establishment2Urn), "The establishment 2 URN is invalid"); } else { viewModel.Establishment2Urn = model.Establishment2Urn; viewModel.Establishment2Name = estab2.GetResult().Name; submittedUrns.Add(model.Establishment2Urn.GetValueOrDefault()); } } if (model.Establishment3Urn.HasValue) { var estab3 = await _establishmentReadService.GetAsync(model.Establishment3Urn.GetValueOrDefault(), User); if (estab3.GetResult() == null) { ViewData.ModelState.AddModelError(nameof(model.Establishment3Urn), "The establishment 3 URN is invalid"); } else { viewModel.Establishment3Urn = model.Establishment3Urn; viewModel.Establishment3Name = estab3.GetResult().Name; submittedUrns.Add(model.Establishment3Urn.GetValueOrDefault()); } } var duplicates = submittedUrns.GroupBy(x => x) .Where(g => g.Count() > 1) .ToDictionary(x => x.Key, x => x.Count()); if (duplicates.ContainsKey(model.Establishment0Urn.GetValueOrDefault())) { ViewData.ModelState.AddModelError("Establishment0Urn", "Duplicate URN. Please correct the URN."); } if (duplicates.ContainsKey(model.Establishment1Urn.GetValueOrDefault())) { ViewData.ModelState.AddModelError("Establishment1Urn", "Duplicate URN. Please correct the URN."); } if (duplicates.ContainsKey(model.Establishment2Urn.GetValueOrDefault())) { ViewData.ModelState.AddModelError("Establishment2Urn", "Duplicate URN. Please correct the URN."); } if (duplicates.ContainsKey(model.Establishment3Urn.GetValueOrDefault())) { ViewData.ModelState.AddModelError("Establishment3Urn", "Duplicate URN. Please correct the URN."); } if (!ModelState.IsValid) { return(View("~/Views/Tools/Mergers/AmalgamateEstablishments.cshtml", model)); } viewModel.EstablishmentPhases = (await _lookupService.EducationPhasesGetAllAsync()).ToSelectList(); viewModel.EstablishmentTypes = (await _lookupService.EstablishmentTypesGetAllAsync()).ToSelectList(); viewModel.LocalAuthorities = (await _lookupService.LocalAuthorityGetAllAsync()).ToSelectList(); return(View("~/Views/Tools/Mergers/ConfirmAmalgamation.cshtml", viewModel)); }