Skip to content

Instantly share code, notes, and snippets.

@laur3d
Created September 21, 2020 07:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save laur3d/afbb960a897165881e8c8f00f5e9ec46 to your computer and use it in GitHub Desktop.
Save laur3d/afbb960a897165881e8c8f00f5e9ec46 to your computer and use it in GitHub Desktop.
[FunctionName("GetCartForSession")]
public static async Task<IActionResult> RunAsync(
[HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "cart/{id}")] HttpRequestMessage req,
Guid id,
[DurableClient] IDurableClient client,
ILogger log)
{
if (id == Guid.Empty)
{
return (ActionResult) new BadRequestObjectResult("The ID is required");
}
var entityId = new EntityId(nameof(ShoppingCartEntity), id.ToString());
var stateResponse = await client.ReadEntityStateAsync<ShoppingCartEntity>(entityId);
if (!stateResponse.EntityExists)
{
return (ActionResult) new NotFoundObjectResult("No cart with this id");
}
var response = stateResponse.EntityState.GetCartItems();
return (ActionResult) new OkObjectResult(response.Result);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment