public IActionResult GetBooksForAuthor(Guid authorId) { if (!_libraryRepository.AuthorExists(authorId)) { return(NotFound()); } var booksForAuthorFromRepo = _libraryRepository.GetBooksForAuthor(authorId); var bookForAuthor = booksForAuthorFromRepo.IfNotNull(x => Mapper.Map <IEnumerable <BookDto> >(x)); if (bookForAuthor.IsNull()) { return(NotFound()); } bookForAuthor = bookForAuthor.Select(book => { book = CreateLinksForBooks(book); return(book); }); var wrapper = new LinkCollectionResourceWrapperDto <BookDto>(bookForAuthor); return(Ok(CreateLinksForBooks(wrapper))); }
public IActionResult GetBooksForAuthor(Guid authorId) { if (!_repo.AuthorExists(authorId)) { return(NotFound( )); } var books = _repo.GetBooksForAuthor(authorId); var booktoReturn = Mapper.Map <IEnumerable <BookDto> > (books) .Select(x => { x = CreateLinksForBook(x); return(x); }); var wrapper = new LinkCollectionResourceWrapperDto <BookDto>(booktoReturn); return(Ok(CreateLinksForBooks(wrapper))); }
private LinkCollectionResourceWrapperDto <BookDto> CreateLinksForBooks(LinkCollectionResourceWrapperDto <BookDto> booksWrapper) { booksWrapper.Links.Add(new LinkDto(_urlHelper.RouteUrl("GetBooksForAuthor", new { }), "self", "GET")); return(booksWrapper); }