示例#1
0
        public IActionResult GetBooksForAuthor(Guid authorid)
        {
            if (!_repo.AuthorExists(authorid))
            {
                return(NotFound());
            }

            var booksForAuthorFromRepo = _repo.GetBooksForAuthor(authorid);

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

            if (booksForAuthor == null)
            {
                return(NotFound());
            }

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

            var wrapper = new LinksCollectionResourceWrapperDto <BooksDto>(booksForAuthor);

            return(Ok(CreateLinksForBooks(wrapper)));
        }
示例#2
0
        private LinksCollectionResourceWrapperDto <BooksDto> CreateLinksForBooks(
            LinksCollectionResourceWrapperDto <BooksDto> booksWrapper)
        {
            // link to self
            booksWrapper.Links.Add(
                new LinkDto(_urlHelper.Link("GetBooksForAuthor",
                                            new { }),
                            "self",
                            "GET"));

            return(booksWrapper);
        }