public IHttpActionResult PostPRODUCT(PRODUCT product) { if (!ModelState.IsValid) { return BadRequest(ModelState); } db.PRODUCT.Add(product); try { db.SaveChanges(); } catch (DbUpdateException) { if (PRODUCTExists(product.id)) { return Conflict(); } else { throw; } } return CreatedAtRoute("DefaultApi", new { id = product.id }, product); }
// PUT api/Product/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; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!PRODUCTExists(id)) { return NotFound(); } else { throw; } } return StatusCode(HttpStatusCode.NoContent); }