public IHttpActionResult PutBook(int id, Book book) { if (!ModelState.IsValid) { return BadRequest(ModelState); } if (id != book.BookId) { return BadRequest(); } db.Entry(book).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!BookExists(id)) { return NotFound(); } else { throw; } } return StatusCode(HttpStatusCode.NoContent); }
public IHttpActionResult PostBook(Book book) { if (!ModelState.IsValid) { return BadRequest(ModelState); } db.Books.Add(book); db.SaveChanges(); return CreatedAtRoute("DefaultApi", new { id = book.BookId }, book); }