public IEnumerable <Author> GetAuthors(AuthorParametes authorParametes) { if (authorParametes == null) { return(GetAuthors()); } if (string.IsNullOrWhiteSpace(authorParametes.MainCategory) && string.IsNullOrWhiteSpace(authorParametes.SearchQwery)) { return(GetAuthors()); } var authors = _context.Authors as IQueryable <Author>; if (!string.IsNullOrWhiteSpace(authorParametes.MainCategory)) { var mainCategory = authorParametes.MainCategory.Trim().ToLower(); authors = authors.Where(a => a.MainCategory.ToLower() == mainCategory); } if (!string.IsNullOrWhiteSpace(authorParametes.SearchQwery)) { var searchQwery = authorParametes.SearchQwery.Trim().ToLower(); authors = authors.Where(a => a.MainCategory.ToLower().Contains(searchQwery) || a.FirstName.ToLower().Contains(searchQwery) || a.LastName.ToLower().Contains(searchQwery)); } return(authors.ToList()); }
public ActionResult <IEnumerable <AuthorDto> > GetAuthors([FromQuery] AuthorParametes authorParametes) { var authorsFromRepo = _courseLibraryRepository.GetAuthors(authorParametes); var authors = _mapper.Map <IEnumerable <AuthorDto> >(authorsFromRepo); return(Ok(authors)); }