protected bool IsRepeatedCommand(IGoodIdentificationMvoCommand command, IEventStoreAggregateId eventStoreAggregateId, IGoodIdentificationMvoState state) { bool repeated = false; if (((IGoodIdentificationMvoStateProperties)state).ProductVersion > command.AggregateVersion) { var lastEvent = EventStore.GetEvent(typeof(IGoodIdentificationMvoEvent), eventStoreAggregateId, command.AggregateVersion); if (lastEvent != null && lastEvent.CommandId == command.CommandId) { repeated = true; } } return(repeated); }
protected virtual void Update(IGoodIdentificationMvoCommand c, Action <IGoodIdentificationMvoAggregate> action) { var aggregateId = c.AggregateId; var state = StateRepository.Get(aggregateId, false); var aggregate = GetGoodIdentificationMvoAggregate(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(IGoodIdentificationMvoCommand c) { return(c.ProductVersion == GoodIdentificationMvoState.VersionZero); }