Esempio n. 1
0
        public IActionResult GetBooksById(int authorid)
        {
            try
            {
                if (!_bookLibraryRepository.AuthorExists(authorid))
                {
                    _logger.LogInformation($"Author with id {authorid} was not found when accessing books.");
                    return(NotFound());
                }

                var bookForAuthor = _bookLibraryRepository.GetBookForAuthors(authorid);

                var bookForAuthorResults = Mapper.Map <IEnumerable <BookDto> >(bookForAuthor);

                return(Ok(bookForAuthorResults));
            }
            catch (Exception ex)
            {
                _logger.LogInformation($"Exeption while getting book for author with id {authorid}.", ex);
                return(StatusCode(500, "A problem happend while handeling your request."));
            }
        }
Esempio n. 2
0
        public ActionResult <IEnumerable <BookDto> > GetBooksForAuthor(Guid authorId)
        {
            if (!_bookLibraryRepository.AuthorExists(authorId))
            {
                return(NotFound());
            }

            var booksForAuthorFromRepo = _bookLibraryRepository.GetBooks(authorId);

            return(Ok(_mapper.Map <IEnumerable <BookDto> >(booksForAuthorFromRepo)));
        }