Skip to content

Instantly share code, notes, and snippets.

@dcomartin
Created Dec 1, 2021
Embed
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),
})
.ToArrayAsync(cancellationToken);
return result;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment