// POST: odata/Customers public async Task<IHttpActionResult> Post(Customer customer) { if (!ModelState.IsValid) { return BadRequest(ModelState); } customer.ObjectState = ObjectState.Added; _customerService.Insert(customer); try { await _unitOfWorkAsync.SaveChangesAsync(); } catch (DbUpdateException) { if (CustomerExists(customer.CustomerID)) { return Conflict(); } throw; } return Created(customer); }
// PUT: odata/Customers(5) public async Task<IHttpActionResult> Put(string key, Customer customer) { if (!ModelState.IsValid) { return BadRequest(ModelState); } if (key != customer.CustomerID) { return BadRequest(); } customer.ObjectState = ObjectState.Modified; _customerService.Update(customer); try { await _unitOfWorkAsync.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CustomerExists(key)) { return NotFound(); } throw; } return Updated(customer); }