public ActionResult <BookReadDTO> CreateBookForAuthor(int authorId, BookCreationDTO book) { var newBook = mapper.Map <BookReadDTO>(repository.AddBook(authorId, mapper.Map <Book>(book))); return(CreatedAtRoute( routeName: "GetBook", routeValues: new { authorId, bookId = newBook.BookId }, value: newBook )); }
[BookResultFilter] // either add filter here or add to GetBook Method. public async Task <ActionResult <Book> > PostBook(BookCreationDTO book) { var bookEntity = _mapper.Map <Book>(book); _bookService.CreateBook(bookEntity); await _bookService.SaveBookEntityAsync(); // Fetch Fresh Book. var freshBook = await _bookService.GetBookAsync(bookEntity.Id); return(CreatedAtAction("GetBook", new { id = freshBook.Id }, freshBook)); }