protected void ThrowOnWrongEvent(IContactMechEvent e) { var id = new System.Text.StringBuilder(); id.Append("[").Append("ContactMech|"); var stateEntityId = this.ContactMechId; // Aggregate Id var eventEntityId = e.ContactMechEventId.ContactMechId; if (stateEntityId != eventEntityId) { throw DomainError.Named("mutateWrongEntity", "Entity Id {0} in state but entity id {1} in event", stateEntityId, eventEntityId); } id.Append(stateEntityId).Append(","); id.Append("]"); var stateVersion = this.Version; var eventVersion = e.ContactMechEventId.Version; if (stateVersion != eventVersion) { throw OptimisticConcurrencyException.Create(stateVersion, eventVersion, id.ToString()); } }
public void AddContactMechEvent(IContactMechEvent e) { _innerStateEvents.Add((ContactMechStateCreatedOrMergePatchedOrDeletedDto)e); }
public virtual ContactMechStateCreatedOrMergePatchedOrDeletedDto ToContactMechStateEventDto(IContactMechEvent stateEvent) { if (stateEvent.EventType == StateEventType.Created) { var e = (IContactMechStateCreated)stateEvent; return(ToContactMechStateCreatedDto(e)); } else if (stateEvent.EventType == StateEventType.MergePatched) { var e = (IContactMechStateMergePatched)stateEvent; return(ToContactMechStateMergePatchedDto(e)); } else if (stateEvent.EventType == StateEventType.Deleted) { var e = (IContactMechStateDeleted)stateEvent; return(ToContactMechStateDeletedDto(e)); } throw DomainError.Named("invalidEventType", String.Format("Invalid state event type: {0}", stateEvent.EventType)); }