public IActionResult Edit(Book book) { if (ModelState.IsValid) { Book editedBook = new Book() { ID = book.ID, Title = book.Title, Author = book.Author, Year = book.Year, Description = book.Description }; _books.Edit(editedBook); return(RedirectToAction("Index")); } return(View(book)); }
// PUT api/Book/5 public IHttpActionResult PutBook(string id, Book book) { string message = "ok"; if (!ModelState.IsValid) { message = "Invalid model data."; // return BadRequest(ModelState); } if (id != book.Id) { message = "bad request!"; //return BadRequest(); } //db.Entry(book).State = EntityState.Modified; try { Book update = bookRepository.Edit(book); // db.SaveChanges(); } catch (Exception ex) { message = ex.Message; } //catch (DbUpdateConcurrencyException) //{ // if (!BookExists(id)) // { // return NotFound(); // } // else // { // throw; // } //} // return StatusCode(HttpStatusCode.NoContent); return(Ok(new { id = book.Id, message = message })); }