protected bool IsRepeatedCommand(IRolePermissionCommand command, IEventStoreAggregateId eventStoreAggregateId, IRolePermissionState state)
        {
            bool repeated = false;

            if (((IRolePermissionStateProperties)state).Version > command.AggregateVersion)
            {
                var lastEvent = EventStore.GetEvent(typeof(IRolePermissionEvent), eventStoreAggregateId, command.AggregateVersion);
                if (lastEvent != null && lastEvent.CommandId == command.CommandId)
                {
                    repeated = true;
                }
            }
            return(repeated);
        }
        protected virtual void Update(IRolePermissionCommand c, Action <IRolePermissionAggregate> action)
        {
            var aggregateId = c.AggregateId;
            var state       = StateRepository.Get(aggregateId, false);
            var aggregate   = GetRolePermissionAggregate(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(IRolePermissionCommand c, Action <IRolePermissionAggregate> action)
        {
            var aggregateId = c.AggregateId;
            var state       = StateRepository.Get(aggregateId);
            var aggregate   = GetRolePermissionAggregate(state);

            var eventStoreAggregateId = ToEventStoreAggregateId(aggregateId);

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

            if (repeated)
            {
                return;
            }

            aggregate.ThrowOnInvalidStateTransition(c);
            action(aggregate);
            EventStore.AppendEvents(eventStoreAggregateId, ((IRolePermissionStateProperties)state).Version, aggregate.Changes, () => { StateRepository.Save(state); });
        }
Example #4
0
 private static bool IsCommandCreate(IRolePermissionCommand c)
 {
     return(c.Version == RolePermissionState.VersionZero);
 }