public VacancySummaries GetVacancySummaries(int pageNumber)
        {
            //Page number coming in increments from 1 rather than 0, the repo expects pages to start at 0 so take one from the passed in value
            var query = new VacancySummaryByStatusQuery()
            {
                PageSize        = PageSize,
                RequestedPage   = pageNumber,
                DesiredStatuses = _desiredStatuses
            };

            int totalRecords;

            var vacancies      = _vacancySummaryService.GetWithStatus(query, out totalRecords);
            var vacancyParties = _providerService.GetVacancyOwnerRelationships(vacancies.Select(v => v.VacancyOwnerRelationshipId).Distinct(), false);
            var employers      = _employerService.GetEmployers(vacancyParties.Values.Select(v => v.EmployerId).Distinct()).ToDictionary(e => e.EmployerId, e => e);
            var providers      = _providerService.GetProviders(vacancies.Select(v => v.ContractOwnerId).Distinct()).ToDictionary(p => p.ProviderId, p => p);
            var categories     = _referenceDataProvider.GetCategories(CategoryStatus.Active, CategoryStatus.PendingClosure).ToList();
            //TODO: workaround to have the indexing partially working. Should be done properly
            var apprenticeshipSummaries =
                vacancies.Where(v => v.VacancyType == VacancyType.Apprenticeship).Select(
                    v =>
            {
                try
                {
                    return(ApprenticeshipSummaryMapper.GetApprenticeshipSummary(v,
                                                                                employers[vacancyParties[v.VacancyOwnerRelationshipId].EmployerId],
                                                                                providers[v.ContractOwnerId],
                                                                                categories, _logService));
                }
                catch (Exception ex)
                {
                    _logService.Error($"Error indexing the apprenticeship vacancy with ID={v.VacancyId}", ex);
                    return(null);
                }
            });

            var traineeshipSummaries =
                vacancies.Where(v => v.VacancyType == VacancyType.Traineeship).Select(
                    v =>
            {
                try
                {
                    return(TraineeshipSummaryMapper.GetTraineeshipSummary(v,
                                                                          employers[vacancyParties[v.VacancyOwnerRelationshipId].EmployerId],
                                                                          providers[v.ContractOwnerId],
                                                                          categories, _logService));
                }
                catch (Exception ex)
                {
                    _logService.Error($"Error indexing the traineeship vacancy with ID={v.VacancyId}", ex);
                    return(null);
                }
            });

            return(new VacancySummaries(apprenticeshipSummaries.Where(s => s != null), traineeshipSummaries.Where(s => s != null)));
        }
 public IList <VacancySummary> GetWithStatus(VacancySummaryByStatusQuery query, out int totalRecords)
 {
     return(_vacancySummaryService.GetWithStatus(query, out totalRecords));
 }