protected bool IsRepeatedCommand(ILocatorTypeCommand command, IEventStoreAggregateId eventStoreAggregateId, ILocatorTypeState state) { bool repeated = false; if (((ILocatorTypeStateProperties)state).Version > command.AggregateVersion) { var lastEvent = EventStore.GetEvent(typeof(ILocatorTypeEvent), eventStoreAggregateId, command.AggregateVersion); if (lastEvent != null && lastEvent.CommandId == command.CommandId) { repeated = true; } } return(repeated); }
protected virtual void Update(ILocatorTypeCommand c, Action <ILocatorTypeAggregate> action) { var aggregateId = c.AggregateId; var state = StateRepository.Get(aggregateId, false); var aggregate = GetLocatorTypeAggregate(state); var eventStoreAggregateId = ToEventStoreAggregateId(aggregateId); var repeated = IsRepeatedCommand(c, eventStoreAggregateId, state); if (repeated) { return; } aggregate.ThrowOnInvalidStateTransition(c); action(aggregate); Persist(eventStoreAggregateId, aggregate, state); }
private static bool IsCommandCreate(ILocatorTypeCommand c) { return(c.Version == LocatorTypeState.VersionZero); }