Created
March 5, 2020 01:55
-
-
Save dcomartin/456ec6f48447ceb92c2294d39214931e 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
using MediatR; | |
using Microsoft.eShopWeb.ApplicationCore.Interfaces; | |
using Microsoft.eShopWeb.ApplicationCore.Specifications; | |
using Microsoft.eShopWeb.Web.ViewModels; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Threading; | |
using System.Threading.Tasks; | |
namespace Microsoft.eShopWeb.Web.Features.MyOrders | |
{ | |
public class GetMyOrdersHandler : IRequestHandler<GetMyOrders, IEnumerable<OrderViewModel>> | |
{ | |
private readonly IOrderRepository _orderRepository; | |
public GetMyOrdersHandler(IOrderRepository orderRepository) | |
{ | |
_orderRepository = orderRepository; | |
} | |
public async Task<IEnumerable<OrderViewModel>> Handle(GetMyOrders request, CancellationToken cancellationToken) | |
{ | |
var specification = new CustomerOrdersWithItemsSpecification(request.UserName); | |
var orders = await _orderRepository.ListAsync(specification); | |
return orders.Select(o => new OrderViewModel | |
{ | |
OrderDate = o.OrderDate, | |
OrderItems = o.OrderItems?.Select(oi => new OrderItemViewModel() | |
{ | |
PictureUrl = oi.ItemOrdered.PictureUri, | |
ProductId = oi.ItemOrdered.CatalogItemId, | |
ProductName = oi.ItemOrdered.ProductName, | |
UnitPrice = oi.UnitPrice, | |
Units = oi.Units | |
}).ToList(), | |
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