Skip to content

Instantly share code, notes, and snippets.

@dcomartin
Created October 26, 2023 19:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dcomartin/33d383d3ecc273305738521f84b51de3 to your computer and use it in GitHub Desktop.
Save dcomartin/33d383d3ecc273305738521f84b51de3 to your computer and use it in GitHub Desktop.
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