public async Task <ActionResult <BookViewModel> > CreateBookAsync([FromBody] BookCreateDTO newBook) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var createdBook = await bookManager.CreateBookAsync(newBook); BookViewModel bookView = Mapper.Mapper.MapBook(createdBook); return(Ok(bookView)); }
public async Task <IActionResult> AddBook(BookViewModel vm) { if (!_bookManager.isIsbnUnique(vm.ISBN)) { await _bookManager.CreateBookAsync(vm.Title, vm.ISBN, vm.Year, vm.Rack, vm.AuthorId, vm.PublisherId, vm.GenresIds, vm.BookCopies); TempData["message"] = string.Format(Constants.BookCreated, vm.Title); return(RedirectToAction("Index", "SearchBooks")); } else { TempData["message"] = string.Format(Constants.BookWrongIsbn, vm.ISBN); return(RedirectToAction("AddBook")); } }