public async Task<IHttpActionResult> PostContact(Contact contact) { if (!ModelState.IsValid) { return BadRequest(ModelState); } db.Contacts.Add(contact); try { await db.SaveChangesAsync(); } catch (DbUpdateException) { if (ContactExists(contact.Id)) { return Conflict(); } else { throw; } } return CreatedAtRoute("DefaultApi", new { id = contact.Id }, contact); }
public async Task<IHttpActionResult> PutContact(Guid id, Contact contact) { if (!ModelState.IsValid) { return BadRequest(ModelState); } if (id != contact.Id) { return BadRequest(); } db.Entry(contact).State = EntityState.Modified; try { await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ContactExists(id)) { return NotFound(); } else { throw; } } return StatusCode(HttpStatusCode.NoContent); }