public virtual void Initialize(IInventoryItemStateCreated stateCreated) { var aggregateId = stateCreated.InventoryItemEventId.InventoryItemId; var state = new InventoryItemState(); state.InventoryItemId = aggregateId; var aggregate = (InventoryItemAggregate)GetInventoryItemAggregate(state); var eventStoreAggregateId = ToEventStoreAggregateId(aggregateId); aggregate.Apply(stateCreated); Persist(eventStoreAggregateId, aggregate, state); }
public virtual IInventoryItemState ToInventoryItemState() { var state = new InventoryItemState(true); state.InventoryItemId = this.InventoryItemId; if (this.OnHandQuantity != null && this.OnHandQuantity.HasValue) { state.OnHandQuantity = this.OnHandQuantity.Value; } if (this.InTransitQuantity != null && this.InTransitQuantity.HasValue) { state.InTransitQuantity = this.InTransitQuantity.Value; } if (this.ReservedQuantity != null && this.ReservedQuantity.HasValue) { state.ReservedQuantity = this.ReservedQuantity.Value; } if (this.OccupiedQuantity != null && this.OccupiedQuantity.HasValue) { state.OccupiedQuantity = this.OccupiedQuantity.Value; } if (this.VirtualQuantity != null && this.VirtualQuantity.HasValue) { state.VirtualQuantity = this.VirtualQuantity.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.ToInventoryItemEntryState()); } } ; return(state); }