Exemple #1
0
        public IActionResult GetBooks(BooksResourceParameters booksResourcesParameters)
        {
            try
            {
                var books = _repository.GetBooks(booksResourcesParameters);

                var previousPageLink = books.HasPrevious
                    ? CreateBooksResourceUri(booksResourcesParameters, ResourceUriType.PreviousPage)
                    : null;

                var nextPageLink = books.HasNext
                    ? CreateBooksResourceUri(booksResourcesParameters, ResourceUriType.NextPage)
                    : null;

                var paginationMetadata = new
                {
                    totalCount       = books.TotalCount,
                    pageSize         = books.PageSize,
                    currentPage      = books.CurrentPage,
                    totalPages       = books.TotalPages,
                    previousPageLink = previousPageLink,
                    nextPageLink     = nextPageLink
                };

                Response.Headers.Add("X-Pagination",
                                     Newtonsoft.Json.JsonConvert.SerializeObject(paginationMetadata));

                return(Ok(Mapper.Map <IEnumerable <BookViewModel> >(books)));
            }
            catch (Exception ex)
            {
                _logger.LogError("Failed to load books : {0}", ex);
            }
            return(BadRequest("Failed to load books"));
        }
Exemple #2
0
        public async Task <IActionResult> GetBooks([FromQuery] BookParams bookParams)
        {
            var books = await _repo.GetBooks(bookParams);

            var booksToReturn = _mapper.Map <IEnumerable <BookForListDto> >(books);

            if (books != null)
            {
                Response.AddPagination(books.CurrentPage, books.PageSize,
                                       books.TotalCount, books.TotalPages);
            }

            return(Ok(booksToReturn));
        }
        public IActionResult Get(int publisherId)
        {
            var books = _rep.GetBooks(publisherId);

            return(Ok(books));
        }