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.")); } }
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))); }