-
-
Save dcomartin/2832f04fd86f8ed2de3e241762424eae to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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