Пример #1
0
        public async Task <CommandResponse> HandleAsync(CreateOrderCommand command)
        {
            var order = new OrderAggregate()
                        .Create(command.Id, command.Owner);

            foreach (var item in command.Products)
            {
                order.AddOrderItem(new OrderItem()
                {
                    UnitPrice = item.UnitPrice,
                    Quantity  = item.Quantity,
                    Name      = item.Name,
                    ProductId = item.ProductId
                });
            }

            await _aggregateRepository.SaveAsync(order);

            return(new CommandResponse()
            {
                Result = order.OrderNumber,
                Events = order.GetChanges()
            });
        }