コード例 #1
0
        private async Task <ActionResult> SearchByTrustLaName(string laName, string tab, bool openOnly = false, string orderby = "", int page = 1, string referrer = "home/index")
        {
            var errorMessage = _valService.ValidateLaNameParameter(laName);

            if (string.IsNullOrEmpty(errorMessage))
            {
                var exactMatch = _laSearchService.SearchExactMatch(laName);
                if (exactMatch != null)
                {
                    laName = exactMatch.Id;
                    return(await Search(null, null, SearchTypes.SEARCH_BY_TRUST_LA_CODE_NAME, null, null, laName, null, openOnly, orderby, page, tab));
                }
                var similarMatch = _laSearchService.SearchContains(laName);
                if (similarMatch.Count == 0)
                {
                    return(ErrorView(SearchTypes.SEARCH_BY_TRUST_LA_CODE_NAME, referrer, SearchErrorMessages.NO_LA_RESULTS));
                }
                TempData["SearchMethod"] = "MAT";
                return(RedirectToAction("Search", "La", new { name = laName, openOnly = openOnly }));
            }
            else
            {
                return(ErrorView(SearchTypes.SEARCH_BY_TRUST_LA_CODE_NAME, referrer, errorMessage));
            }
        }
        /// <summary>
        /// Step 3 - Advanced
        /// </summary>
        /// <param name="urn"></param>
        /// <param name="estType"></param>
        /// <param name="comparisonType"></param>
        /// <param name="areaType"></param>
        /// <param name="lacode"></param>
        /// <returns></returns>
        public ActionResult AdvancedCharacteristics(string urn, ComparisonType comparisonType, EstablishmentType estType, ComparisonArea?areaType, int?lacode,
                                                    string laNameText, BenchmarkCriteria AdvancedCriteria)
        {
            if (areaType == ComparisonArea.LaName && !string.IsNullOrEmpty(laNameText) && lacode == null)
            {
                var exactLaMatch = _laSearchService.SearchExactMatch(laNameText);
                if (exactLaMatch != null)
                {
                    lacode = Int32.Parse(exactLaMatch.id);
                }
            }

            ViewBag.URN            = urn;
            ViewBag.ComparisonType = comparisonType;
            ViewBag.EstType        = estType;
            ViewBag.AreaType       = areaType;
            ViewBag.LaCode         = lacode;

            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)
            };

            if (!IsAreaFieldsValid(areaType, lacode, benchmarkSchool))
            {
                ViewBag.Authorities = _laService.GetLocalAuthorities();
                return(View("ChooseRegion", benchmarkSchool));
            }

            var schoolCharsVM = new SchoolCharacteristicsViewModel(benchmarkSchool, base.ExtractSchoolComparisonListFromCookie(), AdvancedCriteria);

            return(View(schoolCharsVM));
        }
コード例 #3
0
        /// <summary>
        /// Step 3 - Advanced
        /// </summary>
        /// <param name="urn"></param>
        /// <param name="estType"></param>
        /// <param name="comparisonType"></param>
        /// <param name="areaType"></param>
        /// <param name="laCodeName"></param>
        /// <returns></returns>
        public async Task <ActionResult> AdvancedCharacteristics(
            long?urn,
            ComparisonType comparisonType,
            EstablishmentType estType,
            ComparisonArea?areaType,
            string laCodeName,
            BenchmarkCriteria AdvancedCriteria,
            bool excludePartial = false,
            int?laCode          = null)
        {
            if (!areaType.HasValue)
            {
                SchoolViewModel vm = null;
                if (urn.HasValue)
                {
                    vm = new SchoolViewModel(await _contextDataService.GetSchoolDataObjectByUrnAsync(urn.Value), _benchmarkBasketService.GetSchoolBenchmarkList());
                }
                else
                {
                    vm = new SchoolViewModelWithNoDefaultSchool();
                }
                vm.ErrorMessage        = ErrorMessages.SelectAreaType;
                ViewBag.Authorities    = _laService.GetLocalAuthorities();
                ViewBag.URN            = urn;
                ViewBag.ComparisonType = comparisonType;
                ViewBag.EstType        = estType;
                ViewBag.AreaType       = areaType;
                ViewBag.ExcludePartial = excludePartial.ToString();
                return(View("ChooseRegion", vm));
            }


            if (areaType == ComparisonArea.LaCodeName && laCode == null)
            {
                string errorMessage = _valService.ValidateLaCodeNameParameter(laCodeName);

                if (string.IsNullOrEmpty(errorMessage))
                {
                    if (IsNumeric(laCodeName))
                    {
                        laCode = int.Parse(laCodeName);
                        if (!_laSearchService.LaCodesContain(laCode.Value))
                        {
                            errorMessage = SearchErrorMessages.NO_LA_RESULTS;
                        }
                    }
                    else
                    {
                        var exactLaMatch = _laSearchService.SearchExactMatch(laCodeName);
                        if (exactLaMatch == null)
                        {
                            errorMessage = SearchErrorMessages.NO_LA_RESULTS;
                        }
                        else
                        {
                            laCode = int.Parse(exactLaMatch.Id);
                        }
                    }
                }

                if (errorMessage != null)
                {
                    SchoolViewModel vm = null;
                    if (urn.HasValue)
                    {
                        vm = new SchoolViewModel(await _contextDataService.GetSchoolDataObjectByUrnAsync(urn.Value), _benchmarkBasketService.GetSchoolBenchmarkList());
                    }
                    else
                    {
                        vm = new SchoolViewModelWithNoDefaultSchool();
                    }
                    vm.ErrorMessage        = errorMessage;
                    ViewBag.Authorities    = _laService.GetLocalAuthorities();
                    ViewBag.URN            = urn;
                    ViewBag.ComparisonType = comparisonType;
                    ViewBag.EstType        = estType;
                    ViewBag.AreaType       = areaType;
                    ViewBag.ExcludePartial = excludePartial.ToString();
                    return(View("ChooseRegion", vm));
                }
            }

            SchoolViewModel benchmarkSchoolVM;

            if (urn.HasValue)
            {
                benchmarkSchoolVM = new SchoolViewModel(await _contextDataService.GetSchoolDataObjectByUrnAsync(urn.Value), _benchmarkBasketService.GetSchoolBenchmarkList());

                var schoolsLatestFinancialDataModel = await _financialDataService.GetSchoolsLatestFinancialDataModelAsync(benchmarkSchoolVM.Id, benchmarkSchoolVM.EstablishmentType);

                benchmarkSchoolVM.HistoricalFinancialDataModels = new List <FinancialDataModel> {
                    schoolsLatestFinancialDataModel
                };
            }
            else
            {
                benchmarkSchoolVM = new SchoolViewModelWithNoDefaultSchool();
            }

            var schoolCharsVM = new SchoolCharacteristicsViewModel(benchmarkSchoolVM, _benchmarkBasketService.GetSchoolBenchmarkList(), AdvancedCriteria);

            ViewBag.URN                 = urn;
            ViewBag.ComparisonType      = comparisonType;
            ViewBag.EstType             = estType;
            ViewBag.EstTypeDescription  = estType.GetDescription();
            ViewBag.ExcludePartial      = excludePartial.ToString();
            ViewBag.AreaType            = areaType;
            ViewBag.AreaTypeDescription = areaType == ComparisonArea.All ? "All of England" : _laService.GetLaName(laCode.ToString());
            ViewBag.LaCode              = laCode;

            return(View(schoolCharsVM));
        }
        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)));
        }
コード例 #5
0
        public async Task <ActionResult> Search(
            string nameId,
            string searchType,
            string suggestionUrn,
            string locationorpostcode,
            string locationCoordinates,
            string laCodeName,
            decimal?radius,
            bool openOnly   = false,
            string orderby  = "",
            int page        = 1,
            string tab      = "list",
            string referrer = "home/index")
        {
            ViewBag.OpenOnly     = openOnly;
            ViewBag.SearchMethod = "Manual";
            ViewBag.LaCodeName   = laCodeName;

            var comparisonList       = _schoolBenchmarkListService.GetSchoolBenchmarkList();
            var manualComparisonList = _manualBenchmarkListService.GetManualBenchmarkList();

            EdubaseDataObject contextDataObject = null;

            if (!string.IsNullOrEmpty(comparisonList.HomeSchoolUrn))
            {
                await _contextDataService.GetSchoolDataObjectByUrnAsync(int.Parse(comparisonList.HomeSchoolUrn));
            }

            dynamic searchResp = null;
            string  errorMessage;

            switch (searchType)
            {
            case SearchTypes.SEARCH_BY_NAME_ID:
                if (string.IsNullOrEmpty(comparisonList.HomeSchoolUrn))
                {
                    var vm = new SchoolViewModelWithNoDefaultSchool(manualComparisonList);
                    return(View("AddSchoolsManually", vm));
                }
                else
                {
                    var vm = new SchoolViewModel(contextDataObject, comparisonList, manualComparisonList);
                    return(View("AddSchoolsManually", vm));
                }

            case SearchTypes.SEARCH_BY_LA_CODE_NAME:
                if (!IsNumeric(laCodeName))
                {
                    errorMessage = _valService.ValidateLaNameParameterForComparison(laCodeName);
                    if (string.IsNullOrEmpty(errorMessage))
                    {
                        var exactMatch = _laSearchService.SearchExactMatch(laCodeName);
                        if (exactMatch != null)
                        {
                            laCodeName = exactMatch.Id;
                            return(await Search(nameId, searchType, suggestionUrn, locationorpostcode,
                                                locationCoordinates, laCodeName, radius, openOnly, orderby, page, tab));
                        }
                        var similarMatch = _laSearchService.SearchContains(laCodeName);
                        if (similarMatch.Count == 0)
                        {
                            var svm = new SearchViewModel(comparisonList, searchType)
                            {
                                SearchType   = searchType,
                                Authorities  = _laService.GetLocalAuthorities(),
                                ErrorMessage = SearchErrorMessages.NO_LA_RESULTS
                            };
                            return(View("Index", svm));
                        }
                        TempData["SearchMethod"] = "Manual";
                        return(RedirectToAction("Search", "La", new { name = laCodeName, openOnly = openOnly }));
                    }
                    else
                    {
                        var svm = new SearchViewModel(comparisonList, searchType)
                        {
                            SearchType   = searchType,
                            Authorities  = _laService.GetLocalAuthorities(),
                            ErrorMessage = errorMessage
                        };
                        return(View("Index", svm));
                    }
                }
                else
                {
                    errorMessage = _valService.ValidateLaCodeParameterForComparison(laCodeName);
                    if (string.IsNullOrEmpty(errorMessage))
                    {
                        searchResp = await GetSearchResultsAsync(nameId, searchType, locationorpostcode, locationCoordinates, laCodeName, radius, openOnly, orderby, page);

                        int resultCount = searchResp.NumberOfResults;
                        if (resultCount == 0)
                        {
                            var svm = new SearchViewModel(comparisonList, searchType)
                            {
                                SearchType   = searchType,
                                Authorities  = _laService.GetLocalAuthorities(),
                                ErrorMessage = SearchErrorMessages.NO_LA_RESULTS
                            };
                            return(View("Index", svm));
                        }
                        else
                        {
                            ViewBag.manualCount = manualComparisonList?.BenchmarkSchools?.Count();
                            return(View("ManualSearchResults", GetSearchedSchoolViewModelList(searchResp, manualComparisonList, orderby, page, searchType, nameId, locationorpostcode, _laService.GetLaName(laCodeName))));
                        }
                    }
                    else
                    {
                        var svm = new SearchViewModel(comparisonList, searchType)
                        {
                            SearchType   = searchType,
                            Authorities  = _laService.GetLocalAuthorities(),
                            ErrorMessage = errorMessage
                        };
                        return(View("Index", svm));
                    }
                }

            case SearchTypes.SEARCH_BY_LOCATION:
            default:
                errorMessage = _valService.ValidateLocationParameterForComparison(locationorpostcode);
                if (string.IsNullOrEmpty(errorMessage))
                {
                    if (string.IsNullOrEmpty(locationCoordinates))
                    {
                        var result = _locationSearchService.SuggestLocationName(locationorpostcode);
                        switch (result.Matches.Count)
                        {
                        case 0:
                            var svm = new SearchViewModel(comparisonList, searchType)
                            {
                                SearchType   = searchType,
                                Authorities  = _laService.GetLocalAuthorities(),
                                ErrorMessage = SearchErrorMessages.NO_LOCATION_RESULTS
                            };
                            return(View("Index", svm));

                        default:
                            TempData["LocationResults"] = result;
                            TempData["SearchMethod"]    = "Manual";
                            return(RedirectToAction("Suggest", "Location", new { locationOrPostcode = locationorpostcode, openOnly = openOnly }));
                        }
                    }
                    else
                    {
                        searchResp = await GetSearchResultsAsync(nameId, searchType, locationorpostcode, locationCoordinates, laCodeName, radius, openOnly, orderby, page);

                        if (searchResp.NumberOfResults == 0)
                        {
                            var svm = new SearchViewModel(comparisonList, searchType)
                            {
                                SearchType   = searchType,
                                Authorities  = _laService.GetLocalAuthorities(),
                                ErrorMessage = SearchErrorMessages.NO_LOCATION_RESULTS
                            };
                            return(View("Index", svm));
                        }
                        ViewBag.manualCount = manualComparisonList?.BenchmarkSchools?.Count();
                        return(View("ManualSearchResults", GetSearchedSchoolViewModelList(searchResp, manualComparisonList, orderby, page, searchType, nameId, locationorpostcode, _laService.GetLaName(laCodeName))));
                    }
                }
                else
                {
                    var svm = new SearchViewModel(comparisonList, searchType)
                    {
                        SearchType   = searchType,
                        Authorities  = _laService.GetLocalAuthorities(),
                        ErrorMessage = errorMessage
                    };
                    return(View("Index", svm));
                }
            }
        }