public IEnumerable <Author> GetAuthors(AuthorsParameters authorsParameters) { if (string.IsNullOrEmpty(authorsParameters.mainCategory) && string.IsNullOrEmpty(authorsParameters.searchQuery)) { return(GetAuthors()); } var authors = _context.Authors as IQueryable <Author>; if (!string.IsNullOrEmpty(authorsParameters.mainCategory)) { var mainCategory = authorsParameters.mainCategory.Trim(); authors = authors.Where(author => author.MainCategory == mainCategory); } if (!string.IsNullOrEmpty(authorsParameters.searchQuery)) { var searchQuery = authorsParameters.searchQuery.Trim(); authors = authors.Where(author => author.MainCategory.Contains(searchQuery) || author.FirstName.Contains(searchQuery) || author.LastName.Contains(searchQuery)); } return(authors.ToList()); }
public ActionResult <IEnumerable <AuthorDto> > GetAuthors( [FromQuery] AuthorsParameters authorsParameters) { var authors = _courseLibraryRepository.GetAuthors(authorsParameters); var authorsDto = _mapper.Map <IEnumerable <AuthorDto> >(authors); return(Ok(authorsDto)); }