public async Task<IHttpActionResult> PostPerson(Person person) { if (!ModelState.IsValid) { return BadRequest(ModelState); } db.People.Add(person); try { await db.SaveChangesAsync(); } catch (DbUpdateException) { if (PersonExists(person.Id)) { return Conflict(); } else { throw; } } return CreatedAtRoute("DefaultApi", new { id = person.Id }, person); }
public async Task<IHttpActionResult> PutPerson(string id, Person person) { if (!ModelState.IsValid) { return BadRequest(ModelState); } if (id != person.Id) { return BadRequest(); } db.Entry(person).State = System.Data.Entity.EntityState.Modified; try { await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!PersonExists(id)) { return NotFound(); } else { throw; } } return StatusCode(HttpStatusCode.NoContent); }