public IActionResult Post([FromBody] PostAuthorView author) { if (ModelState.IsValid) { _authorService.Post(author); return(Ok(author)); } return(BadRequest(ModelState)); }
public void Post(PostAuthorView author) { var authorModel = Mapper.Map <PostAuthorView, Author>(author); var authorBooksModel = new List <BookAuthor>(); var authorId = _authorRepository.Insert(authorModel); foreach (var book in author.Books) { authorBooksModel.Add(new BookAuthor() { AuthorId = authorId, BookId = book.Id }); } _bookInAuthorRepository.Insert(authorBooksModel); }