Skip to content

Instantly share code, notes, and snippets.

@dcomartin
Created December 1, 2021 22:36
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 dcomartin/2832f04fd86f8ed2de3e241762424eae to your computer and use it in GitHub Desktop.
Save dcomartin/2832f04fd86f8ed2de3e241762424eae to your computer and use it in GitHub Desktop.
public class GetMyOrdersHandler : IRequestHandler<GetMyOrdersQuery, GetMyOrdersViewModel>
{
private readonly CatalogContext _db;
public GetMyOrdersHandler(CatalogContext db)
{
_db = db;
}
public async Task<GetMyOrdersViewModel> Handle(GetMyOrdersQuery request, CancellationToken cancellationToken)
{
var result = new GetMyOrdersViewModel();
result.Orders = await _db.CustomerOrdersWithItems(request.UserName)
.Select(o => new OrderSummaryViewModel
{
OrderDate = o.OrderDate,
OrderNumber = o.Id,
Total = o.OrderItems.Sum(x => x.Units * x.UnitPrice),
})
.ToArrayAsync(cancellationToken);
return result;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment