protected void ThrowOnWrongEvent(ILocatorTypeEvent e) { var id = new System.Text.StringBuilder(); id.Append("[").Append("LocatorType|"); var stateEntityId = this.LocatorTypeId; // Aggregate Id var eventEntityId = e.LocatorTypeEventId.LocatorTypeId; 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.LocatorTypeEventId.Version; if (stateVersion != eventVersion) { throw OptimisticConcurrencyException.Create(stateVersion, eventVersion, id.ToString()); } }
public virtual LocatorTypeStateCreatedOrMergePatchedOrDeletedDto ToLocatorTypeStateEventDto(ILocatorTypeEvent stateEvent) { if (stateEvent.EventType == StateEventType.Created) { var e = (ILocatorTypeStateCreated)stateEvent; return(ToLocatorTypeStateCreatedDto(e)); } else if (stateEvent.EventType == StateEventType.MergePatched) { var e = (ILocatorTypeStateMergePatched)stateEvent; return(ToLocatorTypeStateMergePatchedDto(e)); } else if (stateEvent.EventType == StateEventType.Deleted) { var e = (ILocatorTypeStateDeleted)stateEvent; return(ToLocatorTypeStateDeletedDto(e)); } throw DomainError.Named("invalidEventType", String.Format("Invalid state event type: {0}", stateEvent.EventType)); }
public void AddLocatorTypeEvent(ILocatorTypeEvent e) { _innerStateEvents.Add((LocatorTypeStateCreatedOrMergePatchedOrDeletedDto)e); }