public async Task <SpecificationDatasourceRelationshipSearchResultViewModel> PerformSearch(SearchRequestViewModel request) { var filters = request.Filters.IsNullOrEmpty() ? new ConcurrentDictionary <string, string[]>() : request.Filters; if (filters.ContainsKey("")) { filters.Remove(""); } SearchFilterRequest requestOptions = new SearchFilterRequest() { Page = request.PageNumber.HasValue ? request.PageNumber.Value : 1, PageSize = request.PageSize.HasValue ? request.PageSize.Value : 50, SearchTerm = request.SearchTerm, IncludeFacets = request.IncludeFacets, Filters = filters }; if (request.PageNumber.HasValue && request.PageNumber.Value > 0) { requestOptions.Page = request.PageNumber.Value; } PagedResult <SpecificationDatasourceRelationshipSearchResultItem> pagedResult = await _specsClient.FindSpecificationAndRelationships(requestOptions); if (pagedResult == null) { _logger.Error("Find specification data source relationships HTTP request failed"); } int totalPages = pagedResult.TotalItems / pagedResult.PageSize; if (pagedResult.TotalItems % pagedResult.PageSize > 0) { totalPages++; } int startNumber = ((pagedResult.PageSize * pagedResult.PageNumber) - pagedResult.PageSize) + 1; int endNumber = (pagedResult.PageSize * pagedResult.PageNumber); if (endNumber > pagedResult.TotalItems) { endNumber = pagedResult.TotalItems; } SpecificationDatasourceRelationshipSearchResultViewModel viewModel = new SpecificationDatasourceRelationshipSearchResultViewModel { Items = pagedResult.Items, PagerState = new PagerState(pagedResult.PageNumber, pagedResult.TotalPages), TotalCount = pagedResult.TotalItems, StartItemNumber = startNumber, EndItemNumber = endNumber }; return(viewModel); }