public IList <DomainEvent> Accept(OrderRequest request, Dictionary <String, ProductAggregate> productAggregates)
        {
            var evts = new List <DomainEvent>();

            var evt = OrderAcceptedEvent.FromProto(request, this.OrderID);

            evts.Add(evt);

            foreach (string sku in productAggregates.Keys)
            {
                uint quantity = request.LineItems.ToArray().FirstOrDefault(li => li.SKU == sku).Quantity;
                evts.AddRange(productAggregates[sku].Reserve(this.orderID, request.UserID, quantity));
            }
            return(evts);
        }
Пример #2
0
        public IList <DomainEvent> Accept(OrderRequest request, Dictionary <string, ProductAggregate> productAggregates)
        {
            var evts = new List <DomainEvent>();

            var evt = OrderAcceptedEvent.FromProto(request, this.OrderId);

            evts.Add(evt);

            foreach (var sku in productAggregates.Keys)
            {
                var list = new List <LineItem>();
                foreach (var item in request.LineItems)
                {
                    list.Add(item);
                }
                var quantity = list?.FirstOrDefault(li => li.SKU == sku)?.Quantity;
                evts.AddRange(productAggregates[sku].Reserve(this.orderId, request.UserID, quantity.GetValueOrDefault()));
            }
            return(evts);
        }
        public static OrderAcceptedEvent FromProto(OrderRequest tx, string orderId)
        {
            var evt = new OrderAcceptedEvent
            {
                TaxRate   = tx.TaxRate,
                CreatedOn = tx.CreatedOn,
                UserId    = tx.UserID,
                EventId   = Guid.NewGuid().ToString(),
                OrderId   = orderId,
                LineItems = new List <EventLineItem>()
            };

            foreach (var li in tx.LineItems)
            {
                evt.LineItems.Add(new EventLineItem
                {
                    SKU       = li.SKU,
                    Quantity  = li.Quantity,
                    UnitPrice = li.UnitPrice
                });
            }

            return(evt);
        }