public ActionResult <Book> CreateBook(Book book) { _repository.CreateBook(book); _repository.SaveChanges(); return(CreatedAtRoute(nameof(GetBookById), new { Id = book.BookId }, book)); }
public ActionResult <BookReadDTO> CreateBook(BookCreateDTO createBookDTO) { var bookModel = _bookMapper.Map <BookModel>(createBookDTO); _booksRepo.CreateBook(bookModel); _booksRepo.SaveChanges(); var bookReadDTO = _bookMapper.Map <BookReadDTO>(bookModel); return(CreatedAtRoute(nameof(GetBookById), new { id = bookReadDTO.BookId }, bookReadDTO)); }
public ActionResult <BookReadDto> CreateBook(BookCreateDto bookCreateDto) { if (_repository.IsbnExists(bookCreateDto.ISBN)) { return(Conflict(new { message = $"An existing record with the ISBN '{bookCreateDto.ISBN}' was already found.", type = "https://tools.ietf.org/html/rfc7231#section-6.5.8", status = 409 })); } Book bookModel = _mapper.Map <Book>(bookCreateDto); _repository.CreateBook(bookModel); _repository.SaveChanges(); BookReadDto bookReadDto = _mapper.Map <BookReadDto>(_repository.GetBookById(bookModel.BookId)); return(CreatedAtRoute(nameof(GetBookById), new { id = bookModel.BookId }, bookReadDto)); }
public ActionResult <Book> CreateBook(Book bookToInsert) { _bookRepository.CreateBook(bookToInsert); _bookRepository.SaveChanges(); return(CreatedAtRoute(nameof(GetBookById), new { id = bookToInsert.id }, bookToInsert)); }