// Add new book // POST: /api/book public IHttpActionResult PostBook(Book book) { if (!ModelState.IsValid) { return BadRequest(ModelState); } repo.AddBook(book); return Ok(); }
// Update book // PUT: /api/book/id public IHttpActionResult PutBook(int id, Book book) { if (!ModelState.IsValid) { return BadRequest(ModelState); } if (id != book.BookId) { return BadRequest(); } repo.EditBook(book); return Ok(); }
public void UpdateBook(Book book) { _db.Entry(book).State = EntityState.Modified; }
public void CreateBook(Book book) { _db.Books.Add(book); }
public void AddBook(Book book) { db.Books.Add(book); SaveChanges(); }
public void EditBook(Book book) { db.Entry(book).State = EntityState.Modified; SaveChanges(); }