public CompanySearchResponse Search(CompanySearchRequest request) { ValidateRequest(request); var response = new CompanySearchResponse { Companies = _dbContext.CompanyEntities .OrderBy(c => c.Symbol) .Skip((request.CurrentPage - 1) * request.PageSize) .Take(request.PageSize) .Select(c => Mapper.Map<Company>(c)) .ToList(), TotalItems = _dbContext.CompanyEntities.Count() }; return response; }
private void ValidateRequest(CompanySearchRequest request) { if (request.CurrentPage < 1) request.CurrentPage = 1; if (request.PageSize < 1) request.PageSize = 20; }