public ActionResult<BookDto> CreateBookForAuthor(Guid authorId, BookForCreationDto book) { if (!_restApiRepository.AuthorExists(authorId)) { return NotFound(); } var bookEntity = _mapper.Map<Book>(book); _restApiRepository.AddBook(authorId, bookEntity); _restApiRepository.Save(); var bookToReturn = _mapper.Map<BookDto>(bookEntity); return CreatedAtRoute("GetBookForAuthor", new { authorId, bookId = bookToReturn.Id }, bookToReturn); }
public void AddBook(Guid authorId, Book book) { if (authorId == Guid.Empty) { throw new ArgumentNullException(nameof(authorId)); } if (book == null) { throw new ArgumentNullException(nameof(book)); } book.AuthorId = authorId; _restApiRepository.AddBook(authorId, book); _restApiRepository.Save(); }