public async Task <ICollection <Author> > GetAll(QueryPaginationParameters queryPaginationParameters, string filter = null, string sort = null) { var queryable = _context.Set <Author>().AsQueryable(); if (filter != null) { queryable = queryable.Where(author => author.FirstName.Contains(filter)); } if (sort == "authorId") { queryable = queryable.OrderBy(author => author.AuthorId); } if (sort == "lastName") { queryable = queryable.OrderBy(author => author.LastName); } if (sort == "material") { queryable = queryable.OrderBy(author => author.Material); } return(await queryable .Skip((queryPaginationParameters.PageNumber - 1) *queryPaginationParameters.PageSize) .Take(queryPaginationParameters.PageSize) .AsNoTracking() .ToListAsync()); }
public async Task <IActionResult> GetAuthor([FromQuery] QueryPaginationParameters queryPaginationParameters, [FromQuery] string filter, [FromQuery] string sort) { var author = await _unitOfWork.Author.GetAll(queryPaginationParameters, filter, sort); if (author != null) { _logger.LogInformation("GET api/author => OK"); } else { _logger.LogInformation("GET api/author => NOT OK"); return(NotFound()); } var result = _mapper.Map <IEnumerable <AuthorReadDto> >(author); return(Ok(result)); }