private async Task <TrustViewModel> BuildFullTrustVMAsync(int companyNo, TabType tab, ChartGroupType chartGroup, MatFinancingType matFinancing) { var trustVM = await BuildFinancialTrustVMAsync(companyNo, tab, chartGroup, matFinancing); trustVM.AcademiesInContextList = (await _contexDataService.GetAcademiesByUidAsync(trustVM.UID.GetValueOrDefault())).OrderBy(a => a.EstablishmentName).ToList(); if (trustVM.UID != null) { try { trustVM.TrustHistory = await _trustHistoryService.GetTrustHistoryModelAsync(trustVM.UID.GetValueOrDefault()); } catch (NullReferenceException) { //Do not load trust history if missing } } return(trustVM); }
private async Task <TrustListViewModel> BuildTrustViewModelListFromFoundAcademiesAsync(SearchResultsModel <SchoolSearchResult> academySearchResults, string orderBy, int page, string searchType, string nameKeyword, string locationKeyword, string laKeyword) { var academyTrustList = new List <AcademyTrustViewModel>(); foreach (var academySearchResult in academySearchResults.Results) { if (int.TryParse(academySearchResult.UID, out int uid)) { if (!academyTrustList.Any(t => t.Uid == uid)) { int.TryParse(academySearchResult.CompanyNumber, out int companyNo); var academyTrust = new AcademyTrustViewModel(uid, companyNo, academySearchResult.Trusts, _contextDataService.GetAcademiesByUidAsync(uid)); academyTrustList.Add(academyTrust); } } } foreach (var academyTrust in academyTrustList) { var result = await academyTrust.AcademiesListBuilderTask; academyTrust.AcademiesList = result.Select(a => new SchoolViewModel(a)).OrderBy(a => a.Name).ToList(); } MarkAcademiesInsideSearchArea(academySearchResults, academyTrustList); var trustListViewModel = new TrustListViewModel(academyTrustList, null, searchType, nameKeyword, locationKeyword, laKeyword, orderBy) { Pagination = new Pagination { Start = (SearchDefaults.RESULTS_PER_PAGE * (page - 1)) + 1, Total = academyTrustList.Count, PageLinksPerPage = SearchDefaults.LINKS_PER_PAGE, MaxResultsPerPage = SearchDefaults.SEARCHED_SCHOOLS_MAX, PagedEntityType = PagedEntityType.MAT } }; return(trustListViewModel); }