public IHttpActionResult PostProduct(Product product) { if (!ModelState.IsValid) { return BadRequest(ModelState); } _db.Products.Add(product); _db.SaveChanges(); return CreatedAtRoute("DefaultApi", new { id = product.Id }, product); }
// PUT api/Products/5 public IHttpActionResult PutProduct(int id, Product product) { if (!ModelState.IsValid) { return BadRequest(ModelState); } if (id != product.Id) { return BadRequest(); } //_db.Entry(product).State = EntityState.Modified; _db.MarkAsModified(product); try { _db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!ProductExists(id)) { return NotFound(); } else { throw; } } return StatusCode(HttpStatusCode.NoContent); }
public void MarkAsModified(Product item) { Entry(item).State = EntityState.Modified; }
public void MarkAsModified(Product item) { }