Пример #1
0
        private async Task <TrustListViewModel> GetTrustListViewModelAsync(dynamic trustSearchResults, string orderBy, int page, string searchType, string nameKeyword, string locationKeyword, string laKeyword)
        {
            var academyTrustList = new List <AcademyTrustViewModel>();

            foreach (var result in trustSearchResults.Results)
            {
                int.TryParse(result.CompanyNumber, out int companyNo);
                int.TryParse(result.Uid, out int uid);
                var companyName = result.TrustOrCompanyName;
                IEnumerable <EdubaseDataObject> academiesOfTrust = await _contextDataService.GetAcademiesByCompanyNumberAsync(companyNo);

                var academiesList = academiesOfTrust.Select(a => new SchoolViewModel(a)).OrderBy(a => a.Name).ToList();

                if (academiesList.Count > 0)
                {
                    academyTrustList.Add(new AcademyTrustViewModel(uid, companyNo, companyName, academiesList));
                }
            }

            var trustListViewModel = new TrustListViewModel(academyTrustList, null, searchType, nameKeyword, locationKeyword, laKeyword, orderBy)
            {
                SchoolComparisonList = _schoolBenchmarkListService.GetSchoolBenchmarkList(),

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

            return(trustListViewModel);
        }
Пример #2
0
        private void ApplyTrustLevelOrdering(string orderby, TrustListViewModel trustsVm)
        {
            if (orderby == "MatSchoolNumber")
            {
                trustsVm.ModelList = trustsVm.ModelList.OrderByDescending(t => t.AcademiesList.Count).ToList();
                trustsVm.OrderBy   = orderby;
            }

            if (orderby == "AreaSchoolNumber")
            {
                trustsVm.ModelList = trustsVm.ModelList.OrderByDescending(t => t.AcademiesList.Where(a => a.InsideSearchArea).ToList().Count).ToList();
                trustsVm.OrderBy   = orderby;
            }
        }
Пример #3
0
        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);
        }