Last active
September 5, 2019 04:16
-
-
Save bruceharrison1984/4e1ef4b1edcee531a50f7d1c235b9693 to your computer and use it in GitHub Desktop.
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
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