Skip to content

Instantly share code, notes, and snippets.

@dcomartin
Created October 16, 2024 21:29
Show Gist options
  • Save dcomartin/9bb1be090802ca8aebe2a8a6ea3d2f93 to your computer and use it in GitHub Desktop.
Save dcomartin/9bb1be090802ca8aebe2a8a6ea3d2f93 to your computer and use it in GitHub Desktop.
public async Task<OrderViewModel> Handle(GetOrderDetails request, CancellationToken cancellationToken)
{
var order = await _orderRepository.GetByIdAsync(request.OrderId, cancellationToken);
if (order == null)
{
throw new Exception("This is a land mine.");
}
return new OrderViewModel
{
OrderDate = order.OrderDate,
OrderItems = order.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 = order.Id,
ShippingAddress = order.ShipToAddress,
Total = order.Total()
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment