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