Skip to content

Instantly share code, notes, and snippets.

@laur3d
Created September 21, 2020 07:44
Show Gist options
  • Save laur3d/9f85822fd8a18f77b56b4a1e600bc89e to your computer and use it in GitHub Desktop.
Save laur3d/9f85822fd8a18f77b56b4a1e600bc89e to your computer and use it in GitHub Desktop.
[FunctionName("AddItemToCart")]
public static async Task<ActionResult> RunAsync(
[HttpTrigger(AuthorizationLevel.Function, "post", Route = "cart/{id}/add")] HttpRequestMessage req,
Guid id,
[DurableClient] IDurableEntityClient client )
{
if (id == Guid.Empty)
{
return (ActionResult) new BadRequestObjectResult("Id is required");
}
var entityId = new EntityId(nameof(ShoppingCartEntity), id.ToString());
var data = await req.Content.ReadAsAsync<CartItem>();
await client.SignalEntityAsync<IShoppingCart>(entityId, proxy => proxy.Add(data));
return (ActionResult) new AcceptedResult(); // req.CreateResponse(HttpStatusCode.Accepted);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment