Skip to content

Instantly share code, notes, and snippets.

@alimozdemir
Last active June 8, 2020 16:14
Show Gist options
  • Save alimozdemir/6e439d94f9d6074eebf9078c4dfc2efc to your computer and use it in GitHub Desktop.
Save alimozdemir/6e439d94f9d6074eebf9078c4dfc2efc to your computer and use it in GitHub Desktop.
[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