private async Task <ProviderSearchResponse> PerformSearch(ProviderSearchQuery message)
        {
            var pageNumber = message.Page <= 0 ? 1 : message.Page;

            var hasNonLevyContract = message.IsLevyPayingEmployer == false;

            if (message.DeliveryModes == null)
            {
                message.DeliveryModes = new List <string> {
                    "0", "1", "2"
                };
            }

            var searchResults = await _searchService.SearchProviders(
                message.ApprenticeshipId,
                message.PostCode,
                new Pagination { Page = pageNumber, Take = message.Take },
                message.DeliveryModes,
                hasNonLevyContract,
                message.NationalProvidersOnly,
                message.Order);

            if (searchResults.TotalResults > 0 && !searchResults.Hits.Any())
            {
                var take     = _paginationSettings.DefaultResultsAmount;
                var lastPage = take > 0 ? (int)System.Math.Ceiling((double)searchResults.TotalResults / take) : 1;
                return(new ProviderSearchResponse {
                    StatusCode = ProviderSearchResponseCodes.PageNumberOutOfUpperBound, CurrentPage = lastPage
                });
            }

            if (searchResults.ResponseCode != LocationLookupResponse.Ok)
            {
                _logger.Error(new SearchException($"Error:{searchResults.ResponseCode}"), "Unable to get Providers for search criteria");
            }

            var providerSearchResponse = new ProviderSearchResponse()
            {
                Success     = searchResults.ResponseCode == LocationLookupResponse.Ok,
                CurrentPage = pageNumber,
                Results     = searchResults,
                SearchTerms = message.Keywords,
                ShowOnlyNationalProviders = message.NationalProvidersOnly,
                ShowAllProviders          = message.ShowAll,
                StatusCode = GetResponseCode(searchResults.ResponseCode)
            };

            return(providerSearchResponse);
        }
        public ActionResult <IEnumerable <ProviderSearchResponseItem> > SearchProviders(string keywords, int page = 1)
        {
            try
            {
                var providerSearchResults = _providerSearchService.SearchProviders(keywords, page);
                var response = providerSearchResults.Select(providerSearchResultsItem => _providerMapping.MapToProviderSearchItem(providerSearchResultsItem)).ToList();

                foreach (var providerSearchResponseItem in response)
                {
                    providerSearchResponseItem.Uri = ResolveProviderUri(providerSearchResponseItem.Ukprn);
                }

                return(response);
            }
            catch (Exception e)
            {
                _logger.LogError(e, "/providers/search");
                throw;
            }
        }