protected bool IsRepeatedCommand(IInOutLineMvoCommand command, IEventStoreAggregateId eventStoreAggregateId, IInOutLineMvoState state) { bool repeated = false; if (((IInOutLineMvoStateProperties)state).InOutVersion > command.AggregateVersion) { var lastEvent = EventStore.FindLastEvent(typeof(IInOutLineMvoStateEvent), eventStoreAggregateId, command.AggregateVersion); if (lastEvent != null && lastEvent.CommandId == command.CommandId) { repeated = true; } } return(repeated); }
protected virtual void Update(IInOutLineMvoCommand c, Action <IInOutLineMvoAggregate> action) { var aggregateId = c.AggregateId; var state = StateRepository.Get(aggregateId, false); var aggregate = GetInOutLineMvoAggregate(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(IInOutLineMvoCommand c, Action <IInOutLineMvoAggregate> action) { var aggregateId = c.AggregateId; var state = StateRepository.Get(aggregateId, false); var aggregate = GetInOutLineMvoAggregate(state); var eventStoreAggregateId = ToEventStoreAggregateId(aggregateId); var repeated = IsRepeatedCommand(c, eventStoreAggregateId, state); if (repeated) { return; } aggregate.ThrowOnInvalidStateTransition(c); action(aggregate); EventStore.AppendEvents(eventStoreAggregateId, ((IInOutLineMvoStateProperties)state).InOutVersion, aggregate.Changes, () => { StateRepository.Save(state); }); }
private static bool IsCommandCreate(IInOutLineMvoCommand c) { return(c.InOutVersion == InOutLineMvoState.VersionZero); }