Last active
June 8, 2020 16:14
-
-
Save alimozdemir/6e439d94f9d6074eebf9078c4dfc2efc 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
[HttpPost] | |
public async Task<IActionResult> Post(Entity model) | |
{ | |
_db.Entities.Add(model); | |
await _db.SaveChangesAsync(); | |
return Created(model); | |
} | |
[HttpPatch] | |
public async Task<IActionResult> Patch([FromODataUri] int key, Delta<Entity> model) | |
{ | |
var entity = await _db.Entities.FindAsync(key); | |
model.Patch(entity); | |
_db.SaveChanges(); | |
return Updated(entity); | |
} | |
[HttpPut] | |
public async Task<IActionResult> Put([FromODataUri] int key, Entity entity) | |
{ | |
_db.Entry(entity).State = EntityState.Modified; | |
await _db.SaveChangesAsync(); | |
return Updated(entity); | |
} | |
[HttpDelete] | |
public async Task<IActionResult> Delete([FromODataUri] int key) | |
{ | |
var entity = await _db.Entities.FindAsync(key); | |
_db.Entities.Remove(entity); | |
await _db.SaveChangesAsync(); | |
return StatusCode((int)HttpStatusCode.NoContent); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment