public OrderInfo GetOrder(int orderId) { // Use the order component optimized for reads OrderRead orderWS = new OrderRead(); return(orderWS.GetOrder(orderId)); }
public async Task <IActionResult> Get(Guid id) { var orderId = OrderId.With(id); var domainResult = await _processor.ProcessAsync(new ReadModelByIdQuery <OrderReadModel>(orderId), new CancellationToken()); if (domainResult == null) { return(NotFound()); } var result = new OrderRead { Id = OrderId.With(domainResult.Id).GetGuid(), Username = domainResult.Username, ItemCount = domainResult.ItemCount, PriceTotal = domainResult.PriceTotal }; return(Ok(result)); }
public async Task <IActionResult> GetOrder([FromRoute] int id) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var order = await _context.Orders .AsNoTracking() .Include(o => o.GoodsInOrder) .ThenInclude(g => g.Goods) .FirstOrDefaultAsync(o => o.Id == id); if (order == null) { return(NotFound()); } var result = new OrderRead { Id = order.Id, Date = order.Date, UserId = order.UserId, ShipmentMethod = order.ShipmentMethod, GoodsInOrder = order.GoodsInOrder.Select(g => new GoodsInOrderRead { GoodsId = g.GoodsId, Price = g.Price, Quantity = g.Quantity, Name = g.Goods.Name, Image = g.Goods.Image }) .OrderBy(g => g.GoodsId) }; return(Ok(result)); }