public void Save(IMovementConfirmationLineEvent stateEvent) { CurrentSession.Save(stateEvent); var saveable = stateEvent as ISaveable; if (saveable != null) { saveable.Save(); } }
protected void ThrowOnWrongEvent(IMovementConfirmationLineEvent e) { var id = new System.Text.StringBuilder(); id.Append("[").Append("MovementConfirmationLine|"); var stateEntityIdMovementConfirmationDocumentNumber = (this as IGlobalIdentity <MovementConfirmationLineId>).GlobalId.MovementConfirmationDocumentNumber; var eventEntityIdMovementConfirmationDocumentNumber = e.MovementConfirmationLineEventId.MovementConfirmationDocumentNumber; if (stateEntityIdMovementConfirmationDocumentNumber != eventEntityIdMovementConfirmationDocumentNumber) { throw DomainError.Named("mutateWrongEntity", "Entity Id MovementConfirmationDocumentNumber {0} in state but entity id MovementConfirmationDocumentNumber {1} in event", stateEntityIdMovementConfirmationDocumentNumber, eventEntityIdMovementConfirmationDocumentNumber); } id.Append(stateEntityIdMovementConfirmationDocumentNumber).Append(","); var stateEntityIdLineNumber = (this as IGlobalIdentity <MovementConfirmationLineId>).GlobalId.LineNumber; var eventEntityIdLineNumber = e.MovementConfirmationLineEventId.LineNumber; if (stateEntityIdLineNumber != eventEntityIdLineNumber) { throw DomainError.Named("mutateWrongEntity", "Entity Id LineNumber {0} in state but entity id LineNumber {1} in event", stateEntityIdLineNumber, eventEntityIdLineNumber); } id.Append(stateEntityIdLineNumber).Append(","); id.Append("]"); if (ForReapplying) { return; } var stateVersion = this.Version; var stateEvent = e is IMovementConfirmationLineStateEvent ? (IMovementConfirmationLineStateEvent)e : null; if (e == null) { return; } stateEvent.Version = stateVersion; //var stateEventStateVersion = stateEvent.Version; //if (MovementConfirmationLineState.VersionZero == stateEventStateVersion) //{ // stateEventStateVersion = stateEvent.Version = stateVersion; //} //if (stateVersion != stateEventStateVersion) //{ // throw OptimisticConcurrencyException.Create(stateVersion, stateEventStateVersion, id.ToString()); //} }
protected virtual IMovementConfirmationStateMergePatched Map(IMergePatchMovementConfirmation c) { var stateEventId = new MovementConfirmationEventId(c.DocumentNumber, c.Version); IMovementConfirmationStateMergePatched e = NewMovementConfirmationStateMergePatched(stateEventId); e.MovementDocumentNumber = c.MovementDocumentNumber; e.IsApproved = c.IsApproved; e.ApprovalAmount = c.ApprovalAmount; e.Processed = c.Processed; e.Processing = c.Processing; e.DocumentTypeId = c.DocumentTypeId; e.Description = c.Description; e.Active = c.Active; e.IsPropertyMovementDocumentNumberRemoved = c.IsPropertyMovementDocumentNumberRemoved; e.IsPropertyIsApprovedRemoved = c.IsPropertyIsApprovedRemoved; e.IsPropertyApprovalAmountRemoved = c.IsPropertyApprovalAmountRemoved; e.IsPropertyProcessedRemoved = c.IsPropertyProcessedRemoved; e.IsPropertyProcessingRemoved = c.IsPropertyProcessingRemoved; e.IsPropertyDocumentTypeIdRemoved = c.IsPropertyDocumentTypeIdRemoved; e.IsPropertyDescriptionRemoved = c.IsPropertyDescriptionRemoved; e.IsPropertyActiveRemoved = c.IsPropertyActiveRemoved; e.CommandId = c.CommandId; e.CreatedBy = (string)c.RequesterId; e.CreatedAt = ApplicationContext.Current.TimestampService.Now <DateTime>(); var version = c.Version; foreach (IMovementConfirmationLineCommand innerCommand in c.MovementConfirmationLineCommands) { ThrowOnInconsistentCommands(c, innerCommand); IMovementConfirmationLineEvent innerEvent = Map(innerCommand, c, version, _state); e.AddMovementConfirmationLineEvent(innerEvent); } return(e); }
public virtual void AddMovementConfirmationLineEvent(IMovementConfirmationLineEvent e) { ThrowOnInconsistentEventIds(e); this._movementConfirmationLineEvents[e.MovementConfirmationLineEventId] = e; }
public static void ThrowOnInconsistentEventIds(IMovementConfirmationEvent oe, IMovementConfirmationLineEvent e) { if (!oe.MovementConfirmationEventId.DocumentNumber.Equals(e.MovementConfirmationLineEventId.MovementConfirmationDocumentNumber)) { throw DomainError.Named("inconsistentEventIds", "Outer Id DocumentNumber {0} but inner id MovementConfirmationDocumentNumber {1}", oe.MovementConfirmationEventId.DocumentNumber, e.MovementConfirmationLineEventId.MovementConfirmationDocumentNumber); } }
protected void ThrowOnInconsistentEventIds(IMovementConfirmationLineEvent e) { ThrowOnInconsistentEventIds(this, e); }
public virtual MovementConfirmationLineStateCreatedOrMergePatchedOrRemovedDto ToMovementConfirmationLineStateEventDto(IMovementConfirmationLineEvent stateEvent) { if (stateEvent.EventType == StateEventType.Created) { var e = (IMovementConfirmationLineStateCreated)stateEvent; return(ToMovementConfirmationLineStateCreatedDto(e)); } else if (stateEvent.EventType == StateEventType.MergePatched) { var e = (IMovementConfirmationLineStateMergePatched)stateEvent; return(ToMovementConfirmationLineStateMergePatchedDto(e)); } else if (stateEvent.EventType == StateEventType.Removed) { var e = (IMovementConfirmationLineStateRemoved)stateEvent; return(ToMovementConfirmationLineStateRemovedDto(e)); } throw DomainError.Named("invalidEventType", String.Format("Invalid state event type: {0}", stateEvent.EventType)); }
void IMovementConfirmationStateMergePatched.AddMovementConfirmationLineEvent(IMovementConfirmationLineEvent e) { this._movementConfirmationLineEvents.AddMovementConfirmationLineEvent(e); }
public void AddMovementConfirmationLineEvent(IMovementConfirmationLineEvent e) { _innerStateEvents.Add((MovementConfirmationLineStateCreatedOrMergePatchedOrRemovedDto)e); }