Skip to content

Instantly share code, notes, and snippets.

@dcomartin
Created November 24, 2025 21:59
Show Gist options
  • Select an option

  • Save dcomartin/f0601b4f9892fc97848fe57403cd7c42 to your computer and use it in GitHub Desktop.

Select an option

Save dcomartin/f0601b4f9892fc97848fe57403cd7c42 to your computer and use it in GitHub Desktop.
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