public virtual void When(IShipmentPackageStateCreated e) { ThrowOnWrongEvent(e); this.ShipmentBoxTypeId = e.ShipmentBoxTypeId; this.DateCreated = e.DateCreated; this.BoxLength = e.BoxLength; this.BoxHeight = e.BoxHeight; this.BoxWidth = e.BoxWidth; this.DimensionUomId = e.DimensionUomId; this.Weight = e.Weight; this.WeightUomId = e.WeightUomId; this.InsuredValue = e.InsuredValue; this.Active = (e.Active != null && e.Active.HasValue) ? e.Active.Value : default(bool); this.Deleted = false; this.CreatedBy = e.CreatedBy; this.CreatedAt = e.CreatedAt; foreach (IShipmentPackageContentStateCreated innerEvent in e.ShipmentPackageContentEvents) { IShipmentPackageContentState innerState = this.ShipmentPackageContents.Get(innerEvent.GlobalId.ShipmentItemSeqId, true); innerState.Mutate(innerEvent); } }
protected virtual IShipmentPackageStateCreated Map(ICreateShipmentPackage c) { var stateEventId = new ShipmentPackageEventId(c.ShipmentPackageId, c.Version); IShipmentPackageStateCreated e = NewShipmentPackageStateCreated(stateEventId); e.ShipmentBoxTypeId = c.ShipmentBoxTypeId; e.DateCreated = c.DateCreated; e.BoxLength = c.BoxLength; e.BoxHeight = c.BoxHeight; e.BoxWidth = c.BoxWidth; e.DimensionUomId = c.DimensionUomId; e.Weight = c.Weight; e.WeightUomId = c.WeightUomId; e.InsuredValue = c.InsuredValue; e.Active = c.Active; e.CommandId = c.CommandId; e.CreatedBy = (string)c.RequesterId; e.CreatedAt = ApplicationContext.Current.TimestampService.Now <DateTime>(); var version = c.Version; foreach (ICreateShipmentPackageContent innerCommand in c.ShipmentPackageContents) { ThrowOnInconsistentCommands(c, innerCommand); IShipmentPackageContentStateCreated innerEvent = MapCreate(innerCommand, c, version, _state); e.AddShipmentPackageContentEvent(innerEvent); } return(e); }
public virtual void Initialize(IShipmentPackageStateCreated stateCreated) { var aggregateId = stateCreated.ShipmentPackageEventId.ShipmentPackageId; var state = new ShipmentPackageState(); state.ShipmentPackageId = aggregateId; var aggregate = (ShipmentPackageAggregate)GetShipmentPackageAggregate(state); var eventStoreAggregateId = ToEventStoreAggregateId(aggregateId); aggregate.Apply(stateCreated); Persist(eventStoreAggregateId, aggregate, state); }
public virtual ShipmentPackageStateCreatedDto ToShipmentPackageStateCreatedDto(IShipmentPackageStateCreated e) { var dto = new ShipmentPackageStateCreatedDto(); dto.ShipmentPackageEventId = e.ShipmentPackageEventId; dto.CreatedAt = e.CreatedAt; dto.CreatedBy = e.CreatedBy; dto.CommandId = e.CommandId; dto.ShipmentBoxTypeId = e.ShipmentBoxTypeId; dto.DateCreated = e.DateCreated; dto.BoxLength = e.BoxLength; dto.BoxHeight = e.BoxHeight; dto.BoxWidth = e.BoxWidth; dto.DimensionUomId = e.DimensionUomId; dto.Weight = e.Weight; dto.WeightUomId = e.WeightUomId; dto.InsuredValue = e.InsuredValue; dto.Active = e.Active; var shipmentPackageContentEvents = new List <ShipmentPackageContentStateCreatedDto>(); foreach (var ee in e.ShipmentPackageContentEvents) { ShipmentPackageContentStateCreatedDto eeDto = ShipmentPackageContentStateEventDtoConverter.ToShipmentPackageContentStateCreatedDto(ee); shipmentPackageContentEvents.Add(eeDto); } dto.ShipmentPackageContentEvents = shipmentPackageContentEvents.ToArray(); return(dto); }
void IShipmentPackageState.When(IShipmentPackageStateCreated e) { throw new NotSupportedException(); }
public virtual void Create(ICreateShipmentPackage c) { IShipmentPackageStateCreated e = Map(c); Apply(e); }