Beispiel #1
0
        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);

        }
Beispiel #2
0
        public void AddAuthor(Author author)
        {
            if (author == null)
            {
                throw new ArgumentNullException(nameof(author));
            }

            author.Id = Guid.NewGuid();

            foreach (var book in author.Books)
            {
                book.Id = Guid.NewGuid();
            }
            _restApiRepository.AddAuthor(author);
            _restApiRepository.Save();
        }