protected bool IsRepeatedCommand(IUserClaimMvoCommand command, IEventStoreAggregateId eventStoreAggregateId, IUserClaimMvoState state)
        {
            bool repeated = false;

            if (((IUserClaimMvoStateProperties)state).UserVersion > command.AggregateVersion)
            {
                var lastEvent = EventStore.GetEvent(typeof(IUserClaimMvoEvent), eventStoreAggregateId, command.AggregateVersion);
                if (lastEvent != null && lastEvent.CommandId == command.CommandId)
                {
                    repeated = true;
                }
            }
            return(repeated);
        }
        protected virtual void Update(IUserClaimMvoCommand c, Action <IUserClaimMvoAggregate> action)
        {
            var aggregateId = c.AggregateId;
            var state       = StateRepository.Get(aggregateId, false);
            var aggregate   = GetUserClaimMvoAggregate(state);

            var eventStoreAggregateId = ToEventStoreAggregateId(aggregateId);

            var repeated = IsRepeatedCommand(c, eventStoreAggregateId, state);

            if (repeated)
            {
                return;
            }

            aggregate.ThrowOnInvalidStateTransition(c);
            action(aggregate);
            Persist(eventStoreAggregateId, aggregate, state);
        }
        protected virtual void Update(IUserClaimMvoCommand c, Action <IUserClaimMvoAggregate> action)
        {
            var aggregateId = c.AggregateId;
            var state       = StateRepository.Get(aggregateId);
            var aggregate   = GetUserClaimMvoAggregate(state);

            var eventStoreAggregateId = ToEventStoreAggregateId(aggregateId);

            var repeated = IsRepeatedCommand(c, eventStoreAggregateId, state);

            if (repeated)
            {
                return;
            }

            aggregate.ThrowOnInvalidStateTransition(c);
            action(aggregate);
            EventStore.AppendEvents(eventStoreAggregateId, ((IUserClaimMvoStateProperties)state).UserVersion, aggregate.Changes, () => { StateRepository.Save(state); });
        }
Ejemplo n.º 4
0
 private static bool IsCommandCreate(IUserClaimMvoCommand c)
 {
     return(c.UserVersion == UserClaimMvoState.VersionZero);
 }