示例#1
0
        protected void ThrowOnWrongEvent(IOrganizationStateEvent stateEvent)
        {
            var id = new System.Text.StringBuilder();

            id.Append("[").Append("Organization|");

            var stateEntityId = this.OrganizationId;                    // Aggregate Id
            var eventEntityId = stateEvent.StateEventId.OrganizationId; // EntityBase.Aggregate.GetStateEventIdPropertyIdName();

            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 = stateEvent.StateEventId.Version;

            if (stateVersion != eventVersion)
            {
                throw OptimisticConcurrencyException.Create(stateVersion, eventVersion, id.ToString());
            }
        }
示例#2
0
        protected void ThrowOnWrongEvent(IOrganizationStateEvent stateEvent)
        {
            var stateEntityId = this.OrganizationId;                    // Aggregate Id
            var eventEntityId = stateEvent.StateEventId.OrganizationId; // EntityBase.Aggregate.GetStateEventIdPropertyIdName();

            if (stateEntityId != eventEntityId)
            {
                throw DomainError.Named("mutateWrongEntity", "Entity Id {0} in state but entity id {1} in event", stateEntityId, eventEntityId);
            }

            var stateVersion = this.Version;
            var eventVersion = stateEvent.StateEventId.Version;

            if (stateVersion != eventVersion)
            {
                throw DomainError.Named("concurrencyConflict", "Conflict between state version {0} and event version {1}", stateVersion, eventVersion);
            }
        }
示例#3
0
 public void AddOrganizationEvent(IOrganizationStateEvent e)
 {
     _innerStateEvents.Add((OrganizationStateCreatedOrMergePatchedOrDeletedDto)e);
 }
        public virtual OrganizationStateCreatedOrMergePatchedOrDeletedDto ToOrganizationStateEventDto(IOrganizationStateEvent stateEvent)
        {
            if (stateEvent.StateEventType == StateEventType.Created)
            {
                var e = (IOrganizationStateCreated)stateEvent;
                return(ToOrganizationStateCreatedDto(e));
            }
            else if (stateEvent.StateEventType == StateEventType.MergePatched)
            {
                var e = (IOrganizationStateMergePatched)stateEvent;
                return(ToOrganizationStateMergePatchedDto(e));
            }
            else if (stateEvent.StateEventType == StateEventType.Deleted)
            {
                var e = (IOrganizationStateDeleted)stateEvent;
                return(ToOrganizationStateDeletedDto(e));
            }

            throw DomainError.Named("invalidStateEventType", String.Format("Invalid state event type: {0}", stateEvent.StateEventType));
        }