protected bool IsRepeatedCommand(ISupplierProductCommand command, IEventStoreAggregateId eventStoreAggregateId, ISupplierProductState state)
        {
            bool repeated = false;

            if (((ISupplierProductStateProperties)state).Version > command.AggregateVersion)
            {
                var lastEvent = EventStore.GetEvent(typeof(ISupplierProductEvent), eventStoreAggregateId, command.AggregateVersion);
                if (lastEvent != null && lastEvent.CommandId == command.CommandId)
                {
                    repeated = true;
                }
            }
            return(repeated);
        }
        protected virtual void Update(ISupplierProductCommand c, Action <ISupplierProductAggregate> action)
        {
            var aggregateId = c.AggregateId;
            var state       = StateRepository.Get(aggregateId, false);
            var aggregate   = GetSupplierProductAggregate(state);

            var eventStoreAggregateId = ToEventStoreAggregateId(aggregateId);

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

            if (repeated)
            {
                return;
            }

            aggregate.ThrowOnInvalidStateTransition(c);
            action(aggregate);
            Persist(eventStoreAggregateId, aggregate, state);
        }
Пример #3
0
 private static bool IsCommandCreate(ISupplierProductCommand c)
 {
     return(c.Version == SupplierProductState.VersionZero);
 }