-
-
Save dcomartin/33d383d3ecc273305738521f84b51de3 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 OrderReadService : IOrderReadService | |
{ | |
private readonly OrderContext _context; | |
public OrderReadService(OrderContext context) | |
{ | |
_context = context; | |
} | |
public async Task<OrderResponse?> GetOrderByIdAsync(int orderId) | |
{ | |
var orderResponse = await _context.Orders | |
.Where(x => x.OrderId == orderId) | |
.Select(x => new OrderResponse | |
{ | |
OrderDate = x.OrderDate, | |
OrderItems = x.OrderItems.Select(oi => new OrderItemResponse | |
{ | |
PictureUrl = oi.PictureUrl, | |
ProductId = oi.ProductId, | |
ProductName = oi.ProductName, | |
UnitPrice = oi.UnitPrice, | |
Units = oi.Units | |
}).ToList(), | |
OrderNumber = x.OrderNumber, | |
ShippingAddress = x.ShippingAddress, | |
Total = x.Total() | |
}) | |
.FirstOrDefaultAsync(); | |
return orderResponse; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment