// POST odata/Orders public IHttpActionResult Post(Order order) { if (!ModelState.IsValid) { return BadRequest(ModelState); } db.Orders.Add(order); db.SaveChanges(); return Created(order); }
// PUT odata/Orders(5) public IHttpActionResult Put([FromODataUri] int key, Order order) { if (!ModelState.IsValid) { return BadRequest(ModelState); } if (key != order.OrderId) { return BadRequest(); } db.Entry(order).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!OrderExists(key)) { return NotFound(); } else { throw; } } return Updated(order); }