protected bool IsRepeatedCommand(IAttributeSetInstanceExtensionFieldCommand command, IEventStoreAggregateId eventStoreAggregateId, IAttributeSetInstanceExtensionFieldState state) { bool repeated = false; if (((IAttributeSetInstanceExtensionFieldStateProperties)state).Version > command.AggregateVersion) { var lastEvent = EventStore.GetEvent(typeof(IAttributeSetInstanceExtensionFieldEvent), eventStoreAggregateId, command.AggregateVersion); if (lastEvent != null && lastEvent.CommandId == command.CommandId) { repeated = true; } } return(repeated); }
protected virtual void Update(IAttributeSetInstanceExtensionFieldCommand c, Action <IAttributeSetInstanceExtensionFieldAggregate> action) { var aggregateId = c.AggregateId; var state = StateRepository.Get(aggregateId, false); var aggregate = GetAttributeSetInstanceExtensionFieldAggregate(state); var eventStoreAggregateId = ToEventStoreAggregateId(aggregateId); var repeated = IsRepeatedCommand(c, eventStoreAggregateId, state); if (repeated) { return; } aggregate.ThrowOnInvalidStateTransition(c); action(aggregate); Persist(eventStoreAggregateId, aggregate, state); }
}// END ThrowOnInconsistentCommands ///////////////////// protected virtual IAttributeSetInstanceExtensionFieldStateEvent Map(IAttributeSetInstanceExtensionFieldCommand c, IAttributeSetInstanceExtensionFieldGroupCommand outerCommand, long version, IAttributeSetInstanceExtensionFieldGroupState outerState) { var create = (c.CommandType == CommandType.Create) ? (c as ICreateAttributeSetInstanceExtensionField) : null; if (create != null) { return(MapCreate(create, outerCommand, version, outerState)); } var merge = (c.CommandType == CommandType.MergePatch) ? (c as IMergePatchAttributeSetInstanceExtensionField) : null; if (merge != null) { return(MapMergePatch(merge, outerCommand, version, outerState)); } var remove = (c.CommandType == CommandType.Remove) ? (c as IRemoveAttributeSetInstanceExtensionField) : null; if (remove != null) { return(MapRemove(remove, outerCommand, version)); } throw new NotSupportedException(); }
void IAttributeSetInstanceExtensionFieldCommands.Remove(IAttributeSetInstanceExtensionFieldCommand c) { _innerCommands.Remove((CreateOrMergePatchOrRemoveAttributeSetInstanceExtensionFieldDto)c); }
public void Remove(IAttributeSetInstanceExtensionFieldCommand c) { _innerCommands.Remove(c); }
public void Add(IAttributeSetInstanceExtensionFieldCommand c) { _innerCommands.Add(c); }
protected void ThrowOnInconsistentCommands(IAttributeSetInstanceExtensionFieldGroupCommand command, IAttributeSetInstanceExtensionFieldCommand innerCommand) { var properties = command as ICreateOrMergePatchOrDeleteAttributeSetInstanceExtensionFieldGroup; var innerProperties = innerCommand as ICreateOrMergePatchOrRemoveAttributeSetInstanceExtensionField; if (properties == null || innerProperties == null) { return; } var outerIdName = "Id"; var outerIdValue = properties.Id; var innerGroupIdName = "GroupId"; var innerGroupIdValue = innerProperties.GroupId; SetNullInnerIdOrThrowOnInconsistentIds(innerProperties, innerGroupIdName, innerGroupIdValue, outerIdName, outerIdValue); }// END ThrowOnInconsistentCommands /////////////////////
private static bool IsCommandCreate(IAttributeSetInstanceExtensionFieldCommand c) { return(c.Version == AttributeSetInstanceExtensionFieldState.VersionZero); }