public ActionResult Index() { var comparisonList = base.ExtractSchoolComparisonListFromCookie(); if (comparisonList.BenchmarkSchools.Count > 1) { dynamic dynamicBenchmarkSchools = _contextDataService.GetMultipleSchoolsByUrns(comparisonList.BenchmarkSchools.Select(b => b.Urn.ToString()).ToList()); comparisonList.BenchmarkSchools = new List <BenchmarkSchoolViewModel>(); foreach (var dynamicBenchmarkSchool in dynamicBenchmarkSchools) { var school = new SchoolViewModel(dynamicBenchmarkSchool); var benchmarkSchool = new BenchmarkSchoolViewModel() { Address = school.Address, Name = school.Name, Phase = school.OverallPhase, Type = school.Type, FinancialType = school.FinancialType.ToString(), Urn = school.Id }; comparisonList.BenchmarkSchools.Add(benchmarkSchool); } } else if (comparisonList.BenchmarkSchools.Count == 1) { var dynamicBenchmarkSchool = _contextDataService.GetSchoolByUrn(comparisonList.BenchmarkSchools[0].Urn); comparisonList.BenchmarkSchools = new List <BenchmarkSchoolViewModel>(); var school = new SchoolViewModel(dynamicBenchmarkSchool); var benchmarkSchool = new BenchmarkSchoolViewModel() { Address = school.Address, Name = school.Name, Phase = school.OverallPhase, Type = school.Type, FinancialType = school.FinancialType.ToString(), Urn = school.Id }; comparisonList.BenchmarkSchools.Add(benchmarkSchool); } return(View(comparisonList)); }
private SchoolViewModel InstantiateBenchmarkSchool(string urn) { var benchmarkSchool = new SchoolViewModel(_contextDataService.GetSchoolByUrn(urn), base.ExtractSchoolComparisonListFromCookie()); var latestYear = _financialDataService.GetLatestDataYearPerSchoolType(benchmarkSchool.FinancialType); var term = FormatHelpers.FinancialTermFormatAcademies(latestYear); var document = _financialDataService.GetSchoolDataDocument(urn, term, benchmarkSchool.FinancialType); benchmarkSchool.HistoricalSchoolFinancialDataModels = new List <SchoolFinancialDataModel> { new SchoolFinancialDataModel(urn, term, document, benchmarkSchool.FinancialType) }; return(benchmarkSchool); }
/// <summary> /// Step 0 /// </summary> /// <param name="urn"></param> /// <returns></returns> public ViewResult ComparisonStrategy(int urn) { ViewBag.URN = urn; var benchmarkSchool = new SchoolViewModel(_contextDataService.GetSchoolByUrn(urn.ToString()), null); var cookie = base.UpdateSchoolComparisonListCookie(CompareActions.MAKE_DEFAULT_BENCHMARK, new BenchmarkSchoolViewModel() { Name = benchmarkSchool.Name, Urn = benchmarkSchool.Id, Type = benchmarkSchool.Type, FinancialType = benchmarkSchool.FinancialType.ToString() }); Response.Cookies.Add(cookie); benchmarkSchool.ComparisonList = base.ExtractSchoolComparisonListFromCookie(); return(View(benchmarkSchool)); }
public async Task <ActionResult> Search( string nameId, string trustName, string searchType, string suggestionUrn, string locationorpostcode, string locationCoordinates, string laCodeName, decimal?radius, string orderby = "", int page = 1, string tab = "list") { dynamic searchResp = null; string errorMessage; ViewBag.tab = tab; switch (searchType) { case SearchTypes.SEARCH_BY_NAME_ID: var nameIdSanitized = Regex.Replace(nameId, @"(-|/)", ""); if (IsNumeric(nameIdSanitized)) { errorMessage = _valService.ValidateSchoolIdParameter(nameIdSanitized); if (string.IsNullOrEmpty(errorMessage)) { searchResp = IsLaEstab(nameId) ? _contextDataService.GetSchoolByLaEstab(nameIdSanitized) : _contextDataService.GetSchoolByUrn(nameIdSanitized); if (searchResp == null) { return(View("EmptyResult", new SchoolSearchViewModel(base.ExtractSchoolComparisonListFromCookie(), SearchTypes.SEARCH_BY_NAME_ID))); } nameId = ((Microsoft.Azure.Documents.Document)searchResp).GetPropertyValue <string>("URN"); return(RedirectToAction("Detail", "School", new { urn = nameId })); } else { var searchVM = new SchoolSearchViewModel(base.ExtractSchoolComparisonListFromCookie(), searchType) { SearchType = searchType, ErrorMessage = errorMessage, Authorities = _laService.GetLocalAuthorities() }; return(View("../Home/Index", searchVM)); } } else { if (string.IsNullOrEmpty(_valService.ValidateSchoolIdParameter(suggestionUrn))) { return(RedirectToAction("Detail", "School", new { urn = suggestionUrn })); } errorMessage = _valService.ValidateNameParameter(nameId); if (string.IsNullOrEmpty(errorMessage)) { // first see if we get a match on the word searchResp = await GetSearchResults(nameId, searchType, null, null, null, null, radius, orderby, page); if (searchResp.NumberOfResults == 0) { return(RedirectToActionPermanent("SuggestSchool", "SchoolSearch", new RouteValueDictionary { { "nameId", nameId } })); } } else { var searchVM = new SchoolSearchViewModel(base.ExtractSchoolComparisonListFromCookie(), searchType) { SearchType = searchType, ErrorMessage = errorMessage, Authorities = _laService.GetLocalAuthorities() }; return(View("../Home/Index", searchVM)); } } break; case SearchTypes.SEARCH_BY_TRUST_NAME: errorMessage = _valService.ValidateTrustNameParameter(trustName); if (string.IsNullOrEmpty(errorMessage)) { return(RedirectToAction("Search", "Trust", new { name = trustName })); } else { var searchVM = new SchoolSearchViewModel(base.ExtractSchoolComparisonListFromCookie(), searchType) { SearchType = searchType, ErrorMessage = errorMessage, Authorities = _laService.GetLocalAuthorities() }; return(View("../Home/Index", searchVM)); } case SearchTypes.SEARCH_BY_LA_CODE_NAME: if (!IsNumeric(laCodeName)) { errorMessage = _valService.ValidateLaNameParameter(laCodeName); if (string.IsNullOrEmpty(errorMessage)) { var exactMatch = _laSearchService.SearchExactMatch(laCodeName); if (exactMatch != null) { laCodeName = exactMatch.id; return(await Search(nameId, trustName, searchType, suggestionUrn, locationorpostcode, locationCoordinates, laCodeName, radius, orderby, page, tab)); } return(RedirectToAction("Search", "La", new { name = laCodeName })); } else { var searchVM = new SchoolSearchViewModel(base.ExtractSchoolComparisonListFromCookie(), searchType) { SearchType = searchType, ErrorMessage = errorMessage, Authorities = _laService.GetLocalAuthorities() }; return(View("../Home/Index", searchVM)); } } else { errorMessage = _valService.ValidateLaCodeParameter(laCodeName); if (string.IsNullOrEmpty(errorMessage)) { searchResp = await GetSearchResults(nameId, searchType, null, locationorpostcode, locationCoordinates, laCodeName, radius, orderby, page); int resultCount = searchResp.NumberOfResults; switch (resultCount) { case 0: return(View("EmptyResult", new SchoolSearchViewModel(base.ExtractSchoolComparisonListFromCookie(), searchType))); case 1: return(RedirectToAction("Detail", "School", new { urn = ((Domain.Models.QueryResultsModel)searchResp).Results.First()["URN"] })); } } else { var searchVM = new SchoolSearchViewModel(base.ExtractSchoolComparisonListFromCookie(), searchType) { SearchType = searchType, ErrorMessage = errorMessage, Authorities = _laService.GetLocalAuthorities() }; return(View("../Home/Index", searchVM)); } } break; case SearchTypes.SEARCH_BY_LOCATION: errorMessage = _valService.ValidateLocationParameter(locationorpostcode); if (string.IsNullOrEmpty(errorMessage)) { searchResp = await GetSearchResults(nameId, searchType, null, locationorpostcode, locationCoordinates, laCodeName, radius, orderby, page); int resultCnt = searchResp.NumberOfResults; switch (resultCnt) { case 0: return(View("EmptyResult", new SchoolSearchViewModel(base.ExtractSchoolComparisonListFromCookie(), searchType))); case 1: return(RedirectToAction("Detail", "School", new { urn = ((Domain.Models.QueryResultsModel)searchResp).Results.First()["URN"] })); } } else { var searchVM = new SchoolSearchViewModel(base.ExtractSchoolComparisonListFromCookie(), searchType) { SearchType = searchType, ErrorMessage = errorMessage, Authorities = _laService.GetLocalAuthorities() }; return(View("../Home/Index", searchVM)); } break; } var laName = _laService.GetLaName(laCodeName); return(View("SearchResults", GetSchoolViewModelList(searchResp, orderby, page, searchType, nameId, locationorpostcode, laName))); }
public async Task <ActionResult> Detail(int urn, UnitType unit = UnitType.AbsoluteMoney, CentralFinancingType financing = CentralFinancingType.Include, RevenueGroupType tab = RevenueGroupType.Expenditure, ChartFormat format = ChartFormat.Charts) { ChartGroupType chartGroup; switch (tab) { case RevenueGroupType.Expenditure: chartGroup = ChartGroupType.TotalExpenditure; break; case RevenueGroupType.Income: chartGroup = ChartGroupType.TotalIncome; break; case RevenueGroupType.Balance: chartGroup = ChartGroupType.InYearBalance; break; case RevenueGroupType.Workforce: chartGroup = ChartGroupType.Workforce; break; default: chartGroup = ChartGroupType.All; break; } var schoolDetailsFromEdubase = _contextDataService.GetSchoolByUrn(urn.ToString()); if (schoolDetailsFromEdubase == null) { return(View("EmptyResult", new SchoolSearchViewModel(base.ExtractSchoolComparisonListFromCookie(), SearchTypes.SEARCH_BY_NAME_ID))); } SchoolViewModel schoolVM = await BuildSchoolVMAsync(tab, chartGroup, financing, schoolDetailsFromEdubase); UnitType unitType; switch (tab) { case RevenueGroupType.Workforce: unitType = UnitType.AbsoluteCount; break; case RevenueGroupType.Balance: unitType = unit == UnitType.AbsoluteMoney || unit == UnitType.PerPupil || unit == UnitType.PerTeacher ? unit : UnitType.AbsoluteMoney; break; default: unitType = unit; break; } _fcService.PopulateHistoricalChartsWithSchoolData(schoolVM.HistoricalCharts, schoolVM.HistoricalSchoolFinancialDataModels, (BuildTermsList(schoolVM.FinancialType)).First(), tab, unitType, schoolVM.FinancialType); ViewBag.Tab = tab; ViewBag.ChartGroup = chartGroup; ViewBag.UnitType = unitType; ViewBag.Financing = financing; ViewBag.ChartFormat = format; return(View("Detail", schoolVM)); }