public ActionResult <IEnumerable <AuthorDto> > GetAuthors( [FromQuery] AuthorResourseParameters authorResourseParameters) { var authorsFromRepo = _courseLibraryRepository.GetAuthors(authorResourseParameters); return(Ok(_mapper.Map <IEnumerable <AuthorDto> >(authorsFromRepo))); }
public IEnumerable <Author> GetAuthors(AuthorResourseParameters authorResourseParameters) { if (authorResourseParameters == null) { throw new ArgumentNullException(nameof(authorResourseParameters)); } if (string.IsNullOrWhiteSpace(authorResourseParameters.MainCategory) && string.IsNullOrWhiteSpace(authorResourseParameters.SearchQuery)) { return(GetAuthors()); } var collection = _context.Authors as IQueryable <Author>; if (string.IsNullOrWhiteSpace(authorResourseParameters.MainCategory)) { var mainCategory = authorResourseParameters.MainCategory.Trim(); collection = _context.Authors.Where(a => a.MainCategory == mainCategory); } if (string.IsNullOrWhiteSpace(authorResourseParameters.SearchQuery)) { var searchQuery = authorResourseParameters.SearchQuery.Trim(); collection = collection.Where(a => a.MainCategory.Contains(searchQuery) || a.FirstName.Contains(searchQuery) || a.LastName.Contains(searchQuery)); } return(collection.ToList()); }