Last active
October 1, 2017 01:38
-
-
Save tonysneed/4a34e06ce7e5a9fcd4749739ae83dc91 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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