public IHttpActionResult Post(Product product) { if (!ModelState.IsValid) { return BadRequest(ModelState); } db.Products.Add(product); //db.SaveChanges(); return Created(product); }
// PUT: odata/Products(5) public IHttpActionResult Put([FromODataUri] int key, Product product) { if (!ModelState.IsValid) { return BadRequest(ModelState); } if (!ModelState.IsValid) { return BadRequest(ModelState); } if (key != product.ProductID) { return BadRequest(); } db.Products.Attach(product); db.Entry(product).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!ProductExists(key)) { return NotFound(); } else { throw; } } return Updated(product); }