public IActionResult GetBooksForAuthor(Guid authorId)
        {
            if (!_libraryRepository.AuthorExists(authorId))
            {
                return(NotFound());
            }

            var booksForAuthorFromRepo = _libraryRepository.GetBooksForAuthor(authorId);

            var booksForAuthor = AutoMapper.Mapper.Map <IEnumerable <BookDto> >(booksForAuthorFromRepo);

            booksForAuthor = booksForAuthor.Select(book =>
            {
                book = CreateLinksForBook(book);
                return(book);
            });

            var wrapper = new LinkedCollectionResourceWrapperDto <BookDto>(booksForAuthor);

            return(Ok(CreateLinksForBooks(wrapper)));
        }
Beispiel #2
0
        public IActionResult GetBooksForAuthor(Guid authorId)
        {
            if (!_repository.AuthorExists(authorId))
            {
                return(NotFound());
            }

            var bookEntities = _repository.GetBooksForAuthor(authorId);

            var books = Mapper.Map <IEnumerable <BookDto> >(bookEntities);

            books = books.Select(book =>
            {
                book = CreateLinksForBook(book);
                return(book);
            });

            var wrapper = new LinkedCollectionResourceWrapperDto <BookDto>(books);

            return(Ok(CreateLinksForBooks(wrapper)));
        }
Beispiel #3
0
        public IActionResult GetBooksForAuthor(Guid authorId, [FromHeader(Name = "Accept")] string mediaType)
        {
            if (!_libraryRepository.AuthorExists(authorId))
            {
                return(NotFound());
            }

            var books = _libraryRepository.GetBooksForAuthor(authorId);

            var booksDto = _mapper.Map <IEnumerable <BookDto> >(books);

            if (mediaType == "application/vnd.gabriel.hateoas+json")
            {
                booksDto.ToList().ForEach(b => CreateLinksForBook(b));
                var wrapper = new LinkedCollectionResourceWrapperDto <BookDto>(booksDto);
                CreateLinksForBook(wrapper);
                return(Ok(wrapper));
            }

            return(Ok(booksDto));
        }
        public IActionResult GetBooksForAuthor(Guid authorId)
        {
            var booksForAuthorFromRepo = _libraryRepository.GetBooksForAuthor(authorId);

            if (!_libraryRepository.AuthorExists(authorId))
            {
                return(NotFound());
            }

            var books = Mapper.Map <IEnumerable <BookDto> >(booksForAuthorFromRepo);

            books = books.Select(book => //Change each book from book to book with links
            {
                book = CreateLinksForBook(book);
                return(book);
            });

            // Create links
            var wrapper = new LinkedCollectionResourceWrapperDto <BookDto>(books);

            return(Ok(CreateLinksForBooks(wrapper)));
        }
        public IActionResult GetBooksForAuthor(Guid authorId)
        {
            if (!_libraryRepository.AuthorExists(authorId))
            {
                return(NotFound());
            }
            var booksForAuthorFromRepo = _libraryRepository.GetBooksForAuthor(authorId);
            var booksForAuthor         = Mapper.Map <IEnumerable <BookDto> >(booksForAuthorFromRepo);

            #region CreateLinksForBooks => Supporting HATEOAS (Base and Wrapper Class Approach)
            booksForAuthor = booksForAuthor.Select(book =>
            {
                book = CreateLinksForBook(book);
                return(book);
            });

            var wrapper = new LinkedCollectionResourceWrapperDto <BookDto>(booksForAuthor);
            #endregion

            //  CreateLinksForBooks => Supporting HATEOAS (Base and Wrapper Class Approach)
            return(Ok(CreateLinksForBooks(wrapper)));
        }
 public IActionResult BlockAuthorCreation(Guid id)
 {
     return(_libraryRepository.AuthorExists(id) ?
            new StatusCodeResult(StatusCodes.Status409Conflict) : NotFound());
 }