Example #1
0
        protected void ThrowOnWrongEvent(IRoleStateEvent stateEvent)
        {
            var id = new System.Text.StringBuilder();

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

            var stateEntityId = this.RoleId;                    // Aggregate Id
            var eventEntityId = stateEvent.StateEventId.RoleId; // 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());
            }
        }
Example #2
0
        protected void ThrowOnWrongEvent(IRoleStateEvent stateEvent)
        {
            var stateEntityId = this.RoleId;                    // Aggregate Id
            var eventEntityId = stateEvent.StateEventId.RoleId; // 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);
            }
        }
Example #3
0
 public void AddRoleEvent(IRoleStateEvent e)
 {
     _innerStateEvents.Add((RoleStateCreatedOrMergePatchedOrDeletedDto)e);
 }
Example #4
0
        public virtual RoleStateCreatedOrMergePatchedOrDeletedDto ToRoleStateEventDto(IRoleStateEvent stateEvent)
        {
            if (stateEvent.StateEventType == StateEventType.Created)
            {
                var e = (IRoleStateCreated)stateEvent;
                return(ToRoleStateCreatedDto(e));
            }
            else if (stateEvent.StateEventType == StateEventType.MergePatched)
            {
                var e = (IRoleStateMergePatched)stateEvent;
                return(ToRoleStateMergePatchedDto(e));
            }
            else if (stateEvent.StateEventType == StateEventType.Deleted)
            {
                var e = (IRoleStateDeleted)stateEvent;
                return(ToRoleStateDeletedDto(e));
            }

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