Skip to content

Instantly share code, notes, and snippets.

@tonysneed
Last active October 1, 2017 01:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tonysneed/4a34e06ce7e5a9fcd4749739ae83dc91 to your computer and use it in GitHub Desktop.
Save tonysneed/4a34e06ce7e5a9fcd4749739ae83dc91 to your computer and use it in GitHub Desktop.
// PUT: api/Order
[HttpPut]
public async Task<IActionResult> PutOrder([FromBody] Order order)
{
// Apply changes to context
_context.ApplyChanges(order);
try
{
// Persist changes
await _context.SaveChangesAsync();
}
catch (DbUpdateConcurrencyException)
{
if (!_context.Orders.Any(o => o.OrderId == order.OrderId))
return NotFound();
throw;
}
// Populate reference properties
await _context.LoadRelatedEntitiesAsync(order);
// Reset tracking state to unchanged
_context.AcceptChanges(order);
// Return updated order
return Ok(order);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment