public async Task<IHttpActionResult> PostOrder(Order order) { if (!ModelState.IsValid) { return BadRequest(ModelState); } order.TrackingState = TrackingState.Added; _dbContext.ApplyChanges(order); await _dbContext.SaveChangesAsync(); await _dbContext.LoadRelatedEntitiesAsync(order); order.AcceptChanges(); return CreatedAtRoute("DefaultApi", new { id = order.OrderId }, order); }
public async Task<IHttpActionResult> PutOrder(Order order) { if (!ModelState.IsValid) { return BadRequest(ModelState); } _dbContext.ApplyChanges(order); try { await _dbContext.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!_dbContext.Orders.Any(o => o.OrderId == order.OrderId)) { return Conflict(); } throw; } await _dbContext.LoadRelatedEntitiesAsync(order); order.AcceptChanges(); return Ok(order); }