Skip to content

Instantly share code, notes, and snippets.

Created Mar 5, 2020
What would you like to do?
using System;
using MediatR;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Microsoft.eShopWeb.Infrastructure.Data;
namespace Microsoft.eShopWeb.Web.Features.MyOrders
public class GetMyOrdersHandler : IRequestHandler<GetMyOrders, MyOrdersViewModel>
private readonly CatalogContext _db;
public GetMyOrdersHandler(CatalogContext db)
_db = db;
public async Task<MyOrdersViewModel> Handle(GetMyOrders request, CancellationToken cancellationToken)
var result = new MyOrdersViewModel();
result.Orders = await _db.OrderSummaries
.Where(x => x.BuyerId == request.UserName)
.Select(o => new OrderSummaryViewModel
OrderDate = o.OrderDate,
OrderNumber = o.Id,
Total = o.Total,
.ToArrayAsync(cancellationToken: cancellationToken);
return result;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment