public IHttpActionResult PutContact(int id, Contact contact) { if (!ModelState.IsValid) { return BadRequest(ModelState); } if (id != contact.Id) { return BadRequest(); } db.Entry(contact).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!ContactExists(id)) { return NotFound(); } else { throw; } } return StatusCode(HttpStatusCode.NoContent); }
public IHttpActionResult PostContact(Contact contact) { if (!ModelState.IsValid) { return BadRequest(ModelState); } db.Contacts.Add(contact); db.SaveChanges(); return CreatedAtRoute("DefaultApi", new { id = contact.Id }, contact); }