예제 #1
0
        public async Task <ActionResult> GetAuthorById(int id)
        {
            var spec   = new AuthorsWithBooksSpecification(id);
            var author = await _authorRepository.GetEntityWithSpec(spec);

            if (author == null)
            {
                return(NotFound(new ApiResponse(404)));
            }

            return(Ok(_mapper.Map <Author, AuthorDTO>(author)));
        }
예제 #2
0
        public async Task <ActionResult <IEnumerable <AuthorDTO> > > GetAuthors([FromQuery] AuthorSpecificationParams authorParams)
        {
            var spec = new AuthorsWithBooksSpecification(authorParams);

            // get any overall count of items (after filtering has been applied)
            var countSpec  = new AuthorsWithFiltersForCountSpecification(authorParams);
            var totalItems = await _authorRepository.CountAsync(countSpec);

            // add pagination response headers to help client applications
            _httpContextAccessor.HttpContext.AddPaginationResponseHeaders(totalItems, authorParams.PageSize, authorParams.PageIndex);

            var authors = await _authorRepository.ListAsync(spec);

            return(Ok(_mapper.Map <IEnumerable <Author>, IEnumerable <AuthorDTO> >(authors)));
        }