public async Task <IHttpActionResult> PutAuthor(int id, Author author) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != author.AuthorId) { return(BadRequest()); } db.Entry(author).State = EntityState.Modified; try { await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!AuthorExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public void Put(int id, [FromBody] Author itemNew) { BookStoreDataContext db = new BookStoreDataContext(); var item = db.Authors.SingleOrDefault(p => p.AuthorID.Equals(id)); item.Name = itemNew.Name; db.Update(item); db.SaveChangesAsync(); }
public void Put(int id, [FromBody] Book itemNew) { BookStoreDataContext db = new BookStoreDataContext(); var item = db.Books.SingleOrDefault(p => p.ISBN.Equals(id)); item.CategoryID = itemNew.CategoryID; item.Title = itemNew.Title; item.Photo = itemNew.Photo; item.PublishDate = itemNew.PublishDate; item.Price = itemNew.Price; item.Quantity = itemNew.Quantity; db.Update(item); db.SaveChangesAsync(); }