public PagerViewModel(int totalItems, int itemsPerPage, int currentPage, string captionFormat, string routeName, Dictionary <string, string> otherRouteValues = null)
        {
            CurrentPage      = currentPage;
            TotalPages       = PagingHelper.GetTotalNoOfPages(itemsPerPage, totalItems);
            RouteName        = routeName;
            OtherRouteValues = otherRouteValues ?? new Dictionary <string, string>();

            var displayStart = ((currentPage - 1) * itemsPerPage) + 1;
            var displayEnd   = currentPage == TotalPages ? totalItems : displayStart + itemsPerPage - 1;

            Caption = string.Format(captionFormat, displayStart, displayEnd, totalItems);
        }
Esempio n. 2
0
        public void WhenPagingGivenAPageSizeAndZeroResults_ShouldReturnZeroPages()
        {
            var resultPage = PagingHelper.GetTotalNoOfPages(pageSize: 10, noOfTotalResults: 0);

            resultPage.Should().Be(0);
        }
Esempio n. 3
0
        public void WhenPagingGivenAPageSizeAndTotalResultNo_ShouldReturnTotalPages(int pageSize, int noOfResults, int expectedPageNo)
        {
            var resultPage = PagingHelper.GetTotalNoOfPages(pageSize, noOfResults);

            resultPage.Should().Be(expectedPageNo);
        }
Esempio n. 4
0
        public void WhenPagingGivenAPageSizeAndOneResult_ShouldReturnOnePage()
        {
            var resultPage = PagingHelper.GetTotalNoOfPages(pageSize: 10, noOfTotalResults: 1);

            resultPage.Should().Be(1);
        }
Esempio n. 5
0
        public async Task <LegalEntityViewModel> GetLegalEntityViewModelAsync(VacancyRouteModel vrm, long ukprn, string searchTerm, int?requestedPageNo, long?selectedLegalEntityId = 0)
        {
            const int NotFoundIndex = -1;
            var       setPage       = requestedPageNo.HasValue ? requestedPageNo.Value : 1;

            var vacancy = await Utility.GetAuthorisedVacancyForEditAsync(_providerVacancyClient, _recruitVacancyClient, vrm, RouteNames.LegalEntity_Get);

            var legalEntities = (await GetLegalEntityViewModelsAsync(ukprn, vacancy.EmployerAccountId)).ToList();

            var vm = new LegalEntityViewModel
            {
                TotalNumberOfLegalEntities = legalEntities.Count(),
                SelectedOrganisationId     = vacancy.LegalEntityId,
                PageInfo   = Utility.GetPartOnePageInfo(vacancy),
                SearchTerm = searchTerm
            };

            if (vacancy.LegalEntityId != 0 && (selectedLegalEntityId.HasValue == false || selectedLegalEntityId == 0))
            {
                selectedLegalEntityId = vacancy.LegalEntityId;
            }

            vm.IsPreviouslySelectedLegalEntityStillValid = selectedLegalEntityId.HasValue && legalEntities.Any(le => le.Id == selectedLegalEntityId);

            var filteredLegalEntities = legalEntities
                                        .Where(le => string.IsNullOrEmpty(searchTerm) || le.Name.Contains(searchTerm, StringComparison.OrdinalIgnoreCase))
                                        .OrderBy(v => v.Name)
                                        .ToList();

            var filteredLegalEntitiesTotal = filteredLegalEntities.Count();

            var totalNumberOfPages         = PagingHelper.GetTotalNoOfPages(MaxLegalEntitiesPerPage, filteredLegalEntitiesTotal);
            var indexOfSelectedLegalEntity = selectedLegalEntityId.HasValue
                                            ? filteredLegalEntities.FindIndex(le => le.Id == selectedLegalEntityId.Value) + 1
                                            : NotFoundIndex;

            setPage = GetPageNo(requestedPageNo, setPage, totalNumberOfPages, indexOfSelectedLegalEntity);

            SetFilteredOrganisationsForPage(setPage, vm, filteredLegalEntities);
            SetPager(searchTerm, setPage, vm, filteredLegalEntitiesTotal);

            vm.VacancyEmployerInfoModel = new VacancyEmployerInfoModel
            {
                VacancyId     = vacancy.Id,
                LegalEntityId = vacancy.LegalEntityId == 0 ? (long?)null : vacancy.LegalEntityId
            };

            if (vm.VacancyEmployerInfoModel.LegalEntityId == null && vm.HasOnlyOneOrganisation)
            {
                vm.VacancyEmployerInfoModel.LegalEntityId = vm.Organisations.First().Id;
            }

            if (vacancy.EmployerNameOption.HasValue)
            {
                vm.VacancyEmployerInfoModel.EmployerIdentityOption = vacancy.EmployerNameOption.Value.ConvertToModelOption();
                vm.VacancyEmployerInfoModel.AnonymousName          = vacancy.IsAnonymous ? vacancy.EmployerName : null;
                vm.VacancyEmployerInfoModel.AnonymousReason        = vacancy.IsAnonymous ? vacancy.AnonymousReason : null;
            }

            return(vm);
        }
        public async Task <EmployerViewModel> GetEmployerViewModelAsync(VacancyRouteModel vrm, string searchTerm, int?requestedPageNo, string selectedAccountLegalEntityPublicHashedId)
        {
            const int NotFoundIndex = -1;
            var       setPage       = requestedPageNo.HasValue ? requestedPageNo.Value : 1;

            var getEmployerDataTask = _client.GetEditVacancyInfoAsync(vrm.EmployerAccountId);
            var getVacancyTask      = _utility.GetAuthorisedVacancyForEditAsync(vrm, RouteNames.Employer_Get);
            await Task.WhenAll(getEmployerDataTask, getVacancyTask);

            var employerData = getEmployerDataTask.Result;
            var vacancy      = getVacancyTask.Result;

            var legalEntities = BuildLegalEntityViewModels(employerData, vrm.EmployerAccountId);

            var vm = new EmployerViewModel
            {
                TotalNumberOfLegalEntities = legalEntities.Count(),
                PageInfo               = _utility.GetPartOnePageInfo(vacancy),
                SearchTerm             = searchTerm,
                SelectedOrganisationId = vacancy.AccountLegalEntityPublicHashedId
            };

            if (!string.IsNullOrEmpty(vacancy.AccountLegalEntityPublicHashedId) && string.IsNullOrEmpty(selectedAccountLegalEntityPublicHashedId))
            {
                selectedAccountLegalEntityPublicHashedId = vacancy.AccountLegalEntityPublicHashedId;
            }

            vm.IsPreviouslySelectedLegalEntityStillValid = !string.IsNullOrEmpty(selectedAccountLegalEntityPublicHashedId) && legalEntities.Any(le => le.Id == selectedAccountLegalEntityPublicHashedId);

            var filteredLegalEntities = legalEntities
                                        .Where(le => string.IsNullOrEmpty(searchTerm) || le.Name.Contains(searchTerm, StringComparison.OrdinalIgnoreCase))
                                        .OrderBy(v => v.Name)
                                        .ToList();

            var filteredLegalEntitiesTotal = filteredLegalEntities.Count();

            var totalNumberOfPages         = PagingHelper.GetTotalNoOfPages(MaxLegalEntitiesPerPage, filteredLegalEntitiesTotal);
            var indexOfSelectedLegalEntity = !string.IsNullOrEmpty(selectedAccountLegalEntityPublicHashedId)
                                                ? filteredLegalEntities.FindIndex(le => le.Id == selectedAccountLegalEntityPublicHashedId) + 1
                                                : NotFoundIndex;

            setPage = GetPageNo(requestedPageNo, setPage, totalNumberOfPages, indexOfSelectedLegalEntity);

            SetFilteredOrganisationsForPage(setPage, vm, filteredLegalEntities);
            SetPager(searchTerm, setPage, vm, filteredLegalEntitiesTotal);
            vm.Page = setPage;

            vm.VacancyEmployerInfoModel = new VacancyEmployerInfoModel()
            {
                VacancyId = vacancy.Id,
                AccountLegalEntityPublicHashedId = vacancy.AccountLegalEntityPublicHashedId
            };

            if (vm.VacancyEmployerInfoModel.AccountLegalEntityPublicHashedId == null && vm.HasOnlyOneOrganisation)
            {
                vm.VacancyEmployerInfoModel.AccountLegalEntityPublicHashedId = vm.Organisations.First().Id;
            }

            if (vacancy.EmployerNameOption.HasValue)
            {
                vm.VacancyEmployerInfoModel.EmployerIdentityOption = vacancy.EmployerNameOption.Value.ConvertToModelOption();
                vm.VacancyEmployerInfoModel.AnonymousName          = vacancy.IsAnonymous ? vacancy.EmployerName : null;
                vm.VacancyEmployerInfoModel.AnonymousReason        = vacancy.IsAnonymous ? vacancy.AnonymousReason : null;
            }

            return(vm);
        }
Esempio n. 7
0
        public async Task <GetVacanciesResponse> Handle(GetVacanciesQuery request, CancellationToken cancellationToken)
        {
            var validationErrors = ValidateRequest(request);

            if (validationErrors.Any())
            {
                return(new GetVacanciesResponse {
                    ResultCode = ResponseCode.InvalidRequest, ValidationErrors = validationErrors.Cast <object>().ToList()
                });
            }

            IList <VacancySummaryProjection> vacancies;
            var isRequestingProviderOwnedVacancies = request.Ukprn.HasValue;

            if (isRequestingProviderOwnedVacancies)
            {
                var dashboard = await _queryStoreReader.GetProviderDashboardAsync(request.Ukprn.Value);

                vacancies = dashboard?
                            .Vacancies
                            .Where(vs => vs.EmployerAccountId.Equals(request.EmployerAccountId))
                            .ToList();
            }
            else
            {
                var dashboard = await _queryStoreReader.GetEmployerDashboardAsync(request.EmployerAccountId);

                vacancies = dashboard?.Vacancies.ToList();
            }

            if (vacancies == null || vacancies.Any() == false)
            {
                return(new GetVacanciesResponse {
                    ResultCode = ResponseCode.NotFound
                });
            }

            if (request.LegalEntityId.HasValue)
            {
                vacancies = vacancies.Where(vs => vs.LegalEntityId == request.LegalEntityId.Value).ToList();

                if (vacancies.Any() == false)
                {
                    return(new GetVacanciesResponse {
                        ResultCode = ResponseCode.NotFound
                    });
                }
            }

            var totalVacancies = vacancies.Count;
            var pageNo         = PagingHelper.GetRequestedPageNo(request.PageNo, request.PageSize, totalVacancies);
            var totalPages     = PagingHelper.GetTotalNoOfPages(request.PageSize, totalVacancies);

            var responseVacancies = GetVacanciesForPage(vacancies, pageNo, request.PageSize, isRequestingProviderOwnedVacancies);

            return(new GetVacanciesResponse
            {
                ResultCode = ResponseCode.Success,
                Data = new VacanciesSummary(responseVacancies, request.PageSize, pageNo, totalVacancies, totalPages)
            });
        }