public async Task<IHttpActionResult> PostCustomer(Customer customer) { if (!ModelState.IsValid) { return BadRequest(ModelState); } await customer.Geocode(); db.Customers.Add(customer); try { await db.SaveChangesAsync(); } catch (DbUpdateException) { if (CustomerExists(customer.CustomerId)) { return Conflict(); } else { throw; } } return CreatedAtRoute("DefaultApi", new { id = customer.CustomerId }, customer); }
public async Task<IHttpActionResult> PutCustomer(Guid id, Customer customer) { if (!ModelState.IsValid) { return BadRequest(ModelState); } if (id != customer.CustomerId) { return BadRequest(); } await customer.Geocode(); db.Entry(customer).State = EntityState.Modified; try { await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CustomerExists(id)) { return NotFound(); } else { throw; } } return StatusCode(HttpStatusCode.NoContent); }