public IHttpActionResult Postproduct(product product) { if (!ModelState.IsValid) { return BadRequest(ModelState); } db.products.Add(product); try { db.SaveChanges(); } catch (DbUpdateException) { if (productExists(product.id)) { return Conflict(); } else { throw; } } return CreatedAtRoute("DefaultApi", new { id = product.id }, product); }
public IHttpActionResult Putproduct(Guid 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); }