-
-
Save dcomartin/f0601b4f9892fc97848fe57403cd7c42 to your computer and use it in GitHub Desktop.
This file contains hidden or 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<GetMyOrders, IEnumerable<OrderViewModel>> | |
| { | |
| private readonly CatalogContext _dbContext; | |
| public GetMyOrdersHandler(CatalogContext dbContext) | |
| { | |
| _dbContext = dbContext; | |
| } | |
| public async Task<IEnumerable<OrderViewModel>> Handle(GetMyOrders request, | |
| CancellationToken cancellationToken) | |
| { | |
| var orders = await _dbContext.Orders | |
| .Include(x => x.OrderItems) | |
| .Where(x => x.BuyerId == request.UserName) | |
| .ToArrayAsync(cancellationToken: cancellationToken); | |
| return orders.Select(o => new OrderViewModel | |
| { | |
| OrderDate = o.OrderDate, | |
| OrderNumber = o.Id, | |
| ShippingAddress = o.ShipToAddress, | |
| Total = o.Total() | |
| }); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment