public IHttpActionResult PostCustomer(Customers customer) { if (!ModelState.IsValid) { return BadRequest(ModelState); } db.Customers.Add(customer); try { db.SaveChanges(); } catch (DbUpdateException) { if (CustomerExists(customer.CustomerID)) { return Conflict(); } else { throw; } } return CreatedAtRoute("DefaultApi", new { id = customer.CustomerID }, customer); }
public IHttpActionResult PutCustomer(string id, Customers customer) { if (!ModelState.IsValid) { return BadRequest(ModelState); } if (id != customer.CustomerID) { return BadRequest(); } db.Entry(customer).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!CustomerExists(id)) { return NotFound(); } else { throw; } } return StatusCode(HttpStatusCode.NoContent); }