// PUT odata/ODataContacts(5) public IHttpActionResult Put([FromODataUri] int key, Contact contact) { if (!ModelState.IsValid) { return BadRequest(ModelState); } if (key != contact.Id) { return BadRequest(); } db.Entry(contact).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!ContactExists(key)) { return NotFound(); } else { throw; } } return Updated(contact); }
// POST odata/ODataContacts public IHttpActionResult Post(Contact contact) { if (!ModelState.IsValid) { return BadRequest(ModelState); } db.Contacts.Add(contact); db.SaveChanges(); return Created(contact); }