protected void ThrowOnWrongEvent(IRoleEvent e) { var id = new System.Text.StringBuilder(); id.Append("[").Append("Role|"); var stateEntityId = this.RoleId; // Aggregate Id var eventEntityId = e.RoleEventId.RoleId; 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.RoleEventId.Version; if (stateVersion != eventVersion) { throw OptimisticConcurrencyException.Create(stateVersion, eventVersion, id.ToString()); } }
public virtual RoleStateCreatedOrMergePatchedOrDeletedDto ToRoleStateEventDto(IRoleEvent stateEvent) { if (stateEvent.EventType == StateEventType.Created) { var e = (IRoleStateCreated)stateEvent; return(ToRoleStateCreatedDto(e)); } else if (stateEvent.EventType == StateEventType.MergePatched) { var e = (IRoleStateMergePatched)stateEvent; return(ToRoleStateMergePatchedDto(e)); } else if (stateEvent.EventType == StateEventType.Deleted) { var e = (IRoleStateDeleted)stateEvent; return(ToRoleStateDeletedDto(e)); } throw DomainError.Named("invalidEventType", String.Format("Invalid state event type: {0}", stateEvent.EventType)); }
public void AddRoleEvent(IRoleEvent e) { _innerStateEvents.Add((RoleStateCreatedOrMergePatchedOrDeletedDto)e); }