Skip to content

Instantly share code, notes, and snippets.

@bruceharrison1984
Last active September 5, 2019 04:16
Show Gist options
  • Save bruceharrison1984/4e1ef4b1edcee531a50f7d1c235b9693 to your computer and use it in GitHub Desktop.
Save bruceharrison1984/4e1ef4b1edcee531a50f7d1c235b9693 to your computer and use it in GitHub Desktop.
public class KeyResults
{
private readonly WidgetDbContext _dbContext;
private readonly FunctionWrapper<Widget> _functionWrapper;
public Widgets(WidgetDbContext dbContext, FunctionWrapper<Widget> functionWrapper)
{
_dbContext = dbContext;
_functionWrapper = functionWrapper;
}
[FunctionName("PostWidget")]
public async Task<IActionResult> PostWidget(
[HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = "widgets")] Widget item, HttpRequest req, ILogger log)
{
return await _functionWrapper.Execute(req, item, async () =>
{
log.LogInformation($"posting widget: ${item.Id}");
var newItem = await dbContext.Widgets.AddAsync(item);
await dbContext.SaveChangesAsync();
return new ResponseEnvelopeResult<Widget>(HttpStatusCode.Created, newItem.Entity);
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment