Example #1
0
        private async Task PopulateLookupData(IndSchoolsSearchViewModel viewModel)
        {
            viewModel.LocalAuthorities = await _lookup.LocalAuthorityGetAllAsync();

            viewModel.EstablishmentTypes = await _lookup.EstablishmentTypesGetAllAsync();

            viewModel.EstablishmentStatuses = await _lookup.EstablishmentStatusesGetAllAsync();
        }
Example #2
0
        public async Task <ActionResult> IndependentSchoolsSearchResults(IndSchoolsSearchViewModel viewModel)
        {
            await PopulateLookupData(viewModel);

            viewModel.Results = new PaginatedResult <EstablishmentSearchResultModel>(viewModel.Skip, viewModel.Take,
                                                                                     await _establishmentReadService.SearchAsync(await CreateIndSchoolSearchPayload(viewModel), User));
            HttpContext.Response.Headers.Add("x-count", viewModel.Results.Count.ToString());
            return(PartialView("_IndSchSearchResults", viewModel));
        }
Example #3
0
        public async Task <ActionResult> IndependentSchoolsSearchDownload(IndSchoolsSearchViewModel viewModel)
        {
            var id = await _establishmentDownloadService.SearchWithDownloadGenerationAsync(new EstablishmentSearchDownloadPayload
            {
                SearchPayload = await CreateIndSchoolSearchPayload(viewModel),
                FileFormat    = eFileFormat.XLSX,
                DataSet       = eDataSet.IEBT
            }, User);

            return(RedirectToRoute("IndSchSearchResultsDownload", new { id, viewModel.Mode }));
        }
Example #4
0
        private async Task <EstablishmentSearchPayload> CreateIndSchoolSearchPayload(IndSchoolsSearchViewModel viewModel)
        {
            int[] laIds;
            if (viewModel.SelectedLocalAuthoritySetId.Clean() != null)
            {
                laIds = (await _localAuthoritySetRepository.GetAsync(viewModel.SelectedLocalAuthoritySetId.Clean())).Ids;
            }
            else
            {
                laIds = viewModel.SelectedLocalAuthorityIds.ToArray();
            }

            // Default to large min/max range, so that only those record _with_ a date are shown.
            Func <DateTime?, DateTime?> getMaxDate = (DateTime? dt) => dt.HasValue ? dt : new DateTime(DateTime.UtcNow.Year + 100, 1, 1);
            Func <DateTime?, DateTime?> getMinDate = (DateTime? dt) => dt.HasValue ? dt : new DateTime(DateTime.UtcNow.Year - 100, 1, 1);

            return(new EstablishmentSearchPayload
            {
                Filters = new EstablishmentSearchFilters
                {
                    NextActionRequiredByWELMin = viewModel.IsWelfareMode ? getMinDate(viewModel.MinDate.ToDateTime()) : null,
                    NextActionRequiredByWELMax = viewModel.IsWelfareMode ? getMaxDate(viewModel.MaxDate.ToDateTime()) : null,
                    NextGeneralActionRequiredMin = viewModel.IsGeneralMode ? getMinDate(viewModel.MinDate.ToDateTime()) : null,
                    NextGeneralActionRequiredMax = viewModel.IsGeneralMode ? getMaxDate(viewModel.MaxDate.ToDateTime()) : null,
                    LocalAuthorityIds = laIds,
                    StatusIds = new[] { (int)eLookupEstablishmentStatus.Open, (int)eLookupEstablishmentStatus.OpenButProposedToClose }
                },
                Skip = viewModel.Skip,
                Take = 50,
                Select = new List <string>
                {
                    nameof(EstablishmentSearchResultModel.Name),
                    nameof(EstablishmentSearchResultModel.LocalAuthorityId),
                    nameof(EstablishmentSearchResultModel.Address_CityOrTown),
                    nameof(EstablishmentSearchResultModel.StatusId),
                    nameof(EstablishmentSearchResultModel.TypeId),
                    nameof(EstablishmentSearchResultModel.NextGeneralActionRequired),
                    nameof(EstablishmentSearchResultModel.NextActionRequiredByWEL)
                }
            });
        }
Example #5
0
        public async Task <ActionResult> IndependentSchoolsSearch(IndSchoolsSearchViewModel viewModel)
        {
            await PopulateLookupData(viewModel);

            if (!string.Equals(viewModel.ActionName, IndSchoolsSearchViewModel.ActionSearch))
            {
                ModelState.Clear();
            }

            if (viewModel.MinDate.ToDateTime().HasValue&& viewModel.MaxDate.ToDateTime().HasValue&& viewModel.MinDate.ToDateTime() > viewModel.MaxDate.ToDateTime())
            {
                ModelState.AddModelError("date-range", "Please use a valid date range");
            }

            if (ModelState.IsValid)
            {
                switch (viewModel.ActionName)
                {
                case IndSchoolsSearchViewModel.ActionSearch:
                    return(View("IndependentSchoolsSearchResults", viewModel.SetResults(
                                    new PaginatedResult <EstablishmentSearchResultModel>(viewModel.Skip, viewModel.Take,
                                                                                         await _establishmentReadService.SearchAsync(await CreateIndSchoolSearchPayload(viewModel),
                                                                                                                                     User)))));

                case IndSchoolsSearchViewModel.ActionSaveSet:
                    return(Redirect(string.Concat(Url.RouteUrl("CreatePredefinedLASet"), "?",
                                                  QueryStringHelper.ToQueryString(IndSchoolsSearchViewModel.BindAliasForSelectedLocalAuthorityIds,
                                                                                  viewModel.SelectedLocalAuthorityIds.ToArray()))));

                default:
                    break;
                }
            }

            viewModel.LocalAuthoritySets = (await _localAuthoritySetRepository.GetAllAsync()).Items
                                           .OrderBy(x => x.Title)
                                           .Select(x => new IndSchoolsSearchViewModel.LASetViewModel(x));

            return(View(viewModel));
        }