Exemple #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));
            }
        }
        public ActionResult Search(string name, string orderby = "", int page = 1)
        {
            var filteredResults = _laService.SearchContains(name);

            var vm = new LaListViewModel(filteredResults, base.ExtractSchoolComparisonListFromCookie(), orderby);

            vm.Pagination = new Pagination
            {
                Start             = (SearchDefaults.RESULTS_PER_PAGE * (page - 1)) + 1,
                Total             = filteredResults.Count,
                PageLinksPerPage  = SearchDefaults.LINKS_PER_PAGE,
                MaxResultsPerPage = SearchDefaults.RESULTS_PER_PAGE
            };

            return(View(vm));
        }
        public ActionResult Search(string name, string orderby = "", int page = 1, bool openOnly = false)
        {
            var searchMethod = TempData["SearchMethod"] as string;

            var laModels     = _laService.SearchContains(name);
            var laViewModels = laModels.Select(la => new LaViewModel(la.Id, la.LaName)).ToList();

            var vm = new LaListViewModel(laViewModels, _benchmarkBasketService.GetSchoolBenchmarkList(), orderby, openOnly, searchMethod);

            vm.Pagination = new Pagination
            {
                Start             = (SearchDefaults.RESULTS_PER_PAGE * (page - 1)) + 1,
                Total             = laModels.Count,
                PageLinksPerPage  = SearchDefaults.LINKS_PER_PAGE,
                MaxResultsPerPage = SearchDefaults.RESULTS_PER_PAGE,
                PagedEntityType   = PagedEntityType.LA
            };

            return(View(vm));
        }
Exemple #4
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));
                }
            }
        }