public async Task<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 { await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!BookExists(id)) { return NotFound(); } else { throw; } } return StatusCode(HttpStatusCode.NoContent); }
public async Task<IHttpActionResult> PostBook(Book book) { if (!ModelState.IsValid) { return BadRequest(ModelState); } db.Books.Add(book); await db.SaveChangesAsync(); return CreatedAtRoute("DefaultApi", new { id = book.BookID }, book); }