Skip to content

Instantly share code, notes, and snippets.

Created December 1, 2021 22:36
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
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),
return result;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment