예제 #1
0
        public virtual ISellableInventoryItemState ToSellableInventoryItemState()
        {
            var state = new SellableInventoryItemState(true);

            state.SellableInventoryItemId = this.SellableInventoryItemId;
            if (this.SellableQuantity != null && this.SellableQuantity.HasValue)
            {
                state.SellableQuantity = this.SellableQuantity.Value;
            }
            if (this.Version != null && this.Version.HasValue)
            {
                state.Version = this.Version.Value;
            }
            state.CreatedBy = this.CreatedBy;
            if (this.CreatedAt != null && this.CreatedAt.HasValue)
            {
                state.CreatedAt = this.CreatedAt.Value;
            }
            state.UpdatedBy = this.UpdatedBy;
            if (this.UpdatedAt != null && this.UpdatedAt.HasValue)
            {
                state.UpdatedAt = this.UpdatedAt.Value;
            }
            if (this.Entries != null)
            {
                foreach (var s in this.Entries)
                {
                    state.Entries.AddToSave(s.ToSellableInventoryItemEntryState());
                }
            }
            ;

            return(state);
        }
        public virtual void Initialize(ISellableInventoryItemStateCreated stateCreated)
        {
            var aggregateId = stateCreated.SellableInventoryItemEventId.SellableInventoryItemId;
            var state       = new SellableInventoryItemState();

            state.SellableInventoryItemId = aggregateId;
            var aggregate = (SellableInventoryItemAggregate)GetSellableInventoryItemAggregate(state);

            var eventStoreAggregateId = ToEventStoreAggregateId(aggregateId);

            aggregate.Apply(stateCreated);
            Persist(eventStoreAggregateId, aggregate, state);
        }