Created
January 1, 2019 17:08
-
-
Save khalidabuhakmeh/0993dbb41e15a495daf600d6d373b90f to your computer and use it in GitHub Desktop.
Carter Tweaks
This file contains hidden or 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
// ctx is a CarterContext<T> where T is UpdateActor | |
// this allows the context to run binding and validation | |
// ctx also has property accessors for Request, Response, and other helpers. | |
this.Put<UpdateActor>("/actors/{id:int}", async (ctx) => | |
{ | |
// validation is called once and results are cached for request | |
if (!ctx.IsValid) | |
{ | |
ctx.Response.StatusCode = 422; | |
await res.Negotiate(ctx.GetFormattedErrors()); | |
return; | |
} | |
var actor = db.Actors.Find(ctx.Model.Id); | |
ctx.Bind(actor); | |
await db.SaveChangesAsync(); | |
ctx.Response.StatusCode = 204; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment