Exemplo n.º 1
0
        public ActionResult <IEnumerable <AuthorDto> > GetAuthor([FromQuery] AuthorResourceParamers authorResourceParamers)
        {
            if (authorResourceParamers == null)
            {
                throw new ArgumentNullException(nameof(authorResourceParamers));
            }

            var authorsFromRepository = _repository.GetAuthors(authorResourceParamers);

            List <AuthorDto> authorsDto = _mapper.Map <List <AuthorDto> >(authorsFromRepository);

            return(Ok(authorsDto));
        }
Exemplo n.º 2
0
        public IEnumerable <Author> GetAuthors(AuthorResourceParamers authorResourceParamers)
        {
            var collection = _Context.Authors as IQueryable <Author>;

            if (!string.IsNullOrEmpty(authorResourceParamers.MainCategory))
            {
                collection = collection.Where(n => n.MainCategory == authorResourceParamers.MainCategory.Trim());
            }
            if (!string.IsNullOrEmpty(authorResourceParamers.FirstName))
            {
                collection = collection.Where(n => n.FirstName.Contains(authorResourceParamers.FirstName));
            }

            return(collection.ToList());
        }