protected virtual IItemIssuanceStateCreated MapCreate(ICreateItemIssuance c, IShipmentCommand outerCommand, long version, IShipmentState outerState) { c.RequesterId = outerCommand.RequesterId; var stateEventId = new ItemIssuanceEventId(c.ShipmentId, c.ItemIssuanceSeqId, version); IItemIssuanceStateCreated e = NewItemIssuanceStateCreated(stateEventId); var s = outerState.ItemIssuances.Get(c.ItemIssuanceSeqId, true); e.OrderId = c.OrderId; e.OrderItemSeqId = c.OrderItemSeqId; e.ShipGroupSeqId = c.ShipGroupSeqId; e.ProductId = c.ProductId; e.LocatorId = c.LocatorId; e.AttributeSetInstanceId = c.AttributeSetInstanceId; e.ShipmentItemSeqId = c.ShipmentItemSeqId; e.FixedAssetId = c.FixedAssetId; e.MaintHistSeqId = c.MaintHistSeqId; e.IssuedDateTime = c.IssuedDateTime; e.IssuedByUserLoginId = c.IssuedByUserLoginId; e.Quantity = c.Quantity; e.CancelQuantity = c.CancelQuantity; e.Active = c.Active; e.CreatedBy = (string)c.RequesterId; e.CreatedAt = ApplicationContext.Current.TimestampService.Now <DateTime>(); return(e); }// END Map(ICreate... ////////////////////////////
}// END Map(IMergePatch... //////////////////////////// protected virtual IItemIssuanceStateRemoved MapRemove(IRemoveItemIssuance c, IShipmentCommand outerCommand, long version) { c.RequesterId = outerCommand.RequesterId; var stateEventId = new ItemIssuanceEventId(c.ShipmentId, c.ItemIssuanceSeqId, version); IItemIssuanceStateRemoved e = NewItemIssuanceStateRemoved(stateEventId); e.CreatedBy = (string)c.RequesterId; e.CreatedAt = ApplicationContext.Current.TimestampService.Now <DateTime>(); return(e); }// END Map(IRemove... ////////////////////////////
protected bool IsRepeatedCommand(IShipmentCommand command, IEventStoreAggregateId eventStoreAggregateId, IShipmentState state) { bool repeated = false; if (((IShipmentStateProperties)state).Version > command.AggregateVersion) { var lastEvent = EventStore.GetEvent(typeof(IShipmentEvent), eventStoreAggregateId, command.AggregateVersion); if (lastEvent != null && lastEvent.CommandId == command.CommandId) { repeated = true; } } return(repeated); }
protected virtual IShipmentItemStateCreated MapCreate(ICreateShipmentItem c, IShipmentCommand outerCommand, long version, IShipmentState outerState) { c.RequesterId = outerCommand.RequesterId; var stateEventId = new ShipmentItemEventId(c.ShipmentId, c.ShipmentItemSeqId, version); IShipmentItemStateCreated e = NewShipmentItemStateCreated(stateEventId); var s = outerState.ShipmentItems.Get(c.ShipmentItemSeqId, true); e.ProductId = c.ProductId; e.AttributeSetInstanceId = c.AttributeSetInstanceId; e.Quantity = c.Quantity; e.ShipmentContentDescription = c.ShipmentContentDescription; e.Active = c.Active; e.CreatedBy = (string)c.RequesterId; e.CreatedAt = ApplicationContext.Current.TimestampService.Now <DateTime>(); return(e); }// END Map(ICreate... ////////////////////////////
}// END Map(IMergePatch... //////////////////////////// protected virtual IShipmentReceiptEvent Map(IShipmentReceiptCommand c, IShipmentCommand outerCommand, long version, IShipmentState outerState) { var create = (c.CommandType == CommandType.Create) ? (c as ICreateShipmentReceipt) : null; if (create != null) { return(MapCreate(create, outerCommand, version, outerState)); } var merge = (c.CommandType == CommandType.MergePatch || c.CommandType == null) ? (c as IMergePatchShipmentReceipt) : null; if (merge != null) { return(MapMergePatch(merge, outerCommand, version, outerState)); } throw new NotSupportedException(); }
protected virtual void Update(IShipmentCommand c, Action <IShipmentAggregate> action) { var aggregateId = c.AggregateId; var state = StateRepository.Get(aggregateId, false); var aggregate = GetShipmentAggregate(state); var eventStoreAggregateId = ToEventStoreAggregateId(aggregateId); var repeated = IsRepeatedCommand(c, eventStoreAggregateId, state); if (repeated) { return; } aggregate.ThrowOnInvalidStateTransition(c); action(aggregate); Persist(eventStoreAggregateId, aggregate, state); }
}// END ThrowOnInconsistentCommands ///////////////////// protected void ThrowOnInconsistentCommands(IShipmentCommand command, IItemIssuanceCommand innerCommand) { var properties = command as ICreateOrMergePatchOrDeleteShipment; var innerProperties = innerCommand as ICreateOrMergePatchOrRemoveItemIssuance; if (properties == null || innerProperties == null) { return; } if (innerProperties.ShipmentId == default(string)) { innerProperties.ShipmentId = properties.ShipmentId; } else { var outerShipmentIdName = "ShipmentId"; var outerShipmentIdValue = properties.ShipmentId; var innerShipmentIdName = "ShipmentId"; var innerShipmentIdValue = innerProperties.ShipmentId; ThrowOnInconsistentIds(innerProperties, innerShipmentIdName, innerShipmentIdValue, outerShipmentIdName, outerShipmentIdValue); } }// END ThrowOnInconsistentCommands /////////////////////
}// END Map(IRemove... //////////////////////////// protected virtual IItemIssuanceEvent Map(IItemIssuanceCommand c, IShipmentCommand outerCommand, long version, IShipmentState outerState) { var create = (c.CommandType == CommandType.Create) ? (c as ICreateItemIssuance) : null; if (create != null) { return(MapCreate(create, outerCommand, version, outerState)); } var merge = (c.CommandType == CommandType.MergePatch || c.CommandType == null) ? (c as IMergePatchItemIssuance) : null; if (merge != null) { return(MapMergePatch(merge, outerCommand, version, outerState)); } var remove = (c.CommandType == CommandType.Remove) ? (c as IRemoveItemIssuance) : null; if (remove != null) { return(MapRemove(remove, outerCommand, version)); } throw new NotSupportedException(); }
public ShipmentController(IShipmentCommand command) { _command = command; }
private static bool IsCommandCreate(IShipmentCommand c) { return(c.Version == ShipmentState.VersionZero); }
}// END Map(ICreate... //////////////////////////// protected virtual IShipmentReceiptStateMergePatched MapMergePatch(IMergePatchShipmentReceipt c, IShipmentCommand outerCommand, long version, IShipmentState outerState) { c.RequesterId = outerCommand.RequesterId; var stateEventId = new ShipmentReceiptEventId(c.ShipmentId, c.ReceiptSeqId, version); IShipmentReceiptStateMergePatched e = NewShipmentReceiptStateMergePatched(stateEventId); var s = outerState.ShipmentReceipts.Get(c.ReceiptSeqId); e.ProductId = c.ProductId; e.AttributeSetInstanceId = c.AttributeSetInstanceId; e.LocatorId = c.LocatorId; e.ShipmentItemSeqId = c.ShipmentItemSeqId; e.ShipmentPackageSeqId = c.ShipmentPackageSeqId; e.OrderId = c.OrderId; e.OrderItemSeqId = c.OrderItemSeqId; e.ReturnId = c.ReturnId; e.ReturnItemSeqId = c.ReturnItemSeqId; e.RejectionReasonId = c.RejectionReasonId; e.DamageStatusIds = c.DamageStatusIds; e.DamageReasonId = c.DamageReasonId; e.ReceivedBy = c.ReceivedBy; e.DatetimeReceived = c.DatetimeReceived; e.ItemDescription = c.ItemDescription; e.AcceptedQuantity = c.AcceptedQuantity; e.RejectedQuantity = c.RejectedQuantity; e.DamagedQuantity = c.DamagedQuantity; e.Active = c.Active; e.IsPropertyProductIdRemoved = c.IsPropertyProductIdRemoved; e.IsPropertyAttributeSetInstanceIdRemoved = c.IsPropertyAttributeSetInstanceIdRemoved; e.IsPropertyLocatorIdRemoved = c.IsPropertyLocatorIdRemoved; e.IsPropertyShipmentItemSeqIdRemoved = c.IsPropertyShipmentItemSeqIdRemoved; e.IsPropertyShipmentPackageSeqIdRemoved = c.IsPropertyShipmentPackageSeqIdRemoved; e.IsPropertyOrderIdRemoved = c.IsPropertyOrderIdRemoved; e.IsPropertyOrderItemSeqIdRemoved = c.IsPropertyOrderItemSeqIdRemoved; e.IsPropertyReturnIdRemoved = c.IsPropertyReturnIdRemoved; e.IsPropertyReturnItemSeqIdRemoved = c.IsPropertyReturnItemSeqIdRemoved; e.IsPropertyRejectionReasonIdRemoved = c.IsPropertyRejectionReasonIdRemoved; e.IsPropertyDamageStatusIdsRemoved = c.IsPropertyDamageStatusIdsRemoved; e.IsPropertyDamageReasonIdRemoved = c.IsPropertyDamageReasonIdRemoved; e.IsPropertyReceivedByRemoved = c.IsPropertyReceivedByRemoved; e.IsPropertyDatetimeReceivedRemoved = c.IsPropertyDatetimeReceivedRemoved; e.IsPropertyItemDescriptionRemoved = c.IsPropertyItemDescriptionRemoved; e.IsPropertyAcceptedQuantityRemoved = c.IsPropertyAcceptedQuantityRemoved; e.IsPropertyRejectedQuantityRemoved = c.IsPropertyRejectedQuantityRemoved; e.IsPropertyDamagedQuantityRemoved = c.IsPropertyDamagedQuantityRemoved; e.IsPropertyActiveRemoved = c.IsPropertyActiveRemoved; e.CreatedBy = (string)c.RequesterId; e.CreatedAt = ApplicationContext.Current.TimestampService.Now <DateTime>(); foreach (IShipmentReceiptImageCommand innerCommand in c.ShipmentReceiptImageCommands) { ThrowOnInconsistentCommands(c, innerCommand); IShipmentReceiptImageEvent innerEvent = Map(innerCommand, c, version, s); e.AddShipmentReceiptImageEvent(innerEvent); } return(e); }// END Map(IMergePatch... ////////////////////////////
}// END Map(ICreate... //////////////////////////// protected virtual IShipmentImageStateMergePatched MapMergePatch(IMergePatchShipmentImage c, IShipmentCommand outerCommand, long version, IShipmentState outerState) { c.RequesterId = outerCommand.RequesterId; var stateEventId = new ShipmentImageEventId(c.ShipmentId, c.SequenceId, version); IShipmentImageStateMergePatched e = NewShipmentImageStateMergePatched(stateEventId); var s = outerState.ShipmentImages.Get(c.SequenceId); e.Url = c.Url; e.Active = c.Active; e.IsPropertyUrlRemoved = c.IsPropertyUrlRemoved; e.IsPropertyActiveRemoved = c.IsPropertyActiveRemoved; e.CreatedBy = (string)c.RequesterId; e.CreatedAt = ApplicationContext.Current.TimestampService.Now <DateTime>(); return(e); }// END Map(IMergePatch... ////////////////////////////
public ShipmentController(IShipmentCommand command, AppSettings settings) : base(settings) { _command = command; }
protected virtual IShipmentReceiptStateCreated MapCreate(ICreateShipmentReceipt c, IShipmentCommand outerCommand, long version, IShipmentState outerState) { c.RequesterId = outerCommand.RequesterId; var stateEventId = new ShipmentReceiptEventId(c.ShipmentId, c.ReceiptSeqId, version); IShipmentReceiptStateCreated e = NewShipmentReceiptStateCreated(stateEventId); var s = outerState.ShipmentReceipts.Get(c.ReceiptSeqId, true); e.ProductId = c.ProductId; e.AttributeSetInstanceId = c.AttributeSetInstanceId; e.LocatorId = c.LocatorId; e.ShipmentItemSeqId = c.ShipmentItemSeqId; e.ShipmentPackageSeqId = c.ShipmentPackageSeqId; e.OrderId = c.OrderId; e.OrderItemSeqId = c.OrderItemSeqId; e.ReturnId = c.ReturnId; e.ReturnItemSeqId = c.ReturnItemSeqId; e.RejectionReasonId = c.RejectionReasonId; e.DamageStatusId = c.DamageStatusId; e.DamageReasonId = c.DamageReasonId; e.ReceivedBy = c.ReceivedBy; e.DatetimeReceived = c.DatetimeReceived; e.ItemDescription = c.ItemDescription; e.AcceptedQuantity = c.AcceptedQuantity; e.RejectedQuantity = c.RejectedQuantity; e.DamagedQuantity = c.DamagedQuantity; e.Active = c.Active; e.CreatedBy = (string)c.RequesterId; e.CreatedAt = ApplicationContext.Current.TimestampService.Now <DateTime>(); return(e); }// END Map(ICreate... ////////////////////////////