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