Exemple #1
0
        protected bool IsRepeatedCommand(IOrganizationCommand command, IEventStoreAggregateId eventStoreAggregateId, IOrganizationState state)
        {
            bool repeated = false;

            if (((IOrganizationStateProperties)state).Version > command.AggregateVersion)
            {
                var lastEvent = EventStore.FindLastEvent(typeof(IOrganizationStateEvent), eventStoreAggregateId, command.AggregateVersion);
                if (lastEvent != null && lastEvent.CommandId == command.CommandId)
                {
                    repeated = true;
                }
            }
            return(repeated);
        }
Exemple #2
0
        protected virtual void Update(IOrganizationCommand c, Action <IOrganizationAggregate> action)
        {
            var aggregateId = c.AggregateId;
            var state       = StateRepository.Get(aggregateId, false);
            var aggregate   = GetOrganizationAggregate(state);

            var eventStoreAggregateId = ToEventStoreAggregateId(aggregateId);

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

            if (repeated)
            {
                return;
            }

            aggregate.ThrowOnInvalidStateTransition(c);
            action(aggregate);
            EventStore.AppendEvents(eventStoreAggregateId, ((IOrganizationStateProperties)state).Version, aggregate.Changes, () => { StateRepository.Save(state); });
        }
Exemple #3
0
 private static bool IsCommandCreate(IOrganizationCommand c)
 {
     return(c.Version == OrganizationState.VersionZero);
 }