Exemple #1
0
        }// END Map(IMergePatch... ////////////////////////////

        protected virtual IPicklistItemStateRemoved MapRemove(IRemovePicklistItem c, IPicklistBinCommand outerCommand, long version)
        {
            c.RequesterId = outerCommand.RequesterId;
            var stateEventId            = new PicklistItemEventId(c.PicklistBinId, c.PicklistItemOrderShipGrpInvId, version);
            IPicklistItemStateRemoved e = NewPicklistItemStateRemoved(stateEventId);


            e.CreatedBy = (string)c.RequesterId;
            e.CreatedAt = ApplicationContext.Current.TimestampService.Now <DateTime>();

            return(e);
        }// END Map(IRemove... ////////////////////////////
Exemple #2
0
        protected bool IsRepeatedCommand(IPicklistBinCommand command, IEventStoreAggregateId eventStoreAggregateId, IPicklistBinState state)
        {
            bool repeated = false;

            if (((IPicklistBinStateProperties)state).Version > command.AggregateVersion)
            {
                var lastEvent = EventStore.GetEvent(typeof(IPicklistBinEvent), eventStoreAggregateId, command.AggregateVersion);
                if (lastEvent != null && lastEvent.CommandId == command.CommandId)
                {
                    repeated = true;
                }
            }
            return(repeated);
        }
Exemple #3
0
        protected virtual IPicklistItemStateCreated MapCreate(ICreatePicklistItem c, IPicklistBinCommand outerCommand, long version, IPicklistBinState outerState)
        {
            c.RequesterId = outerCommand.RequesterId;
            var stateEventId            = new PicklistItemEventId(c.PicklistBinId, c.PicklistItemOrderShipGrpInvId, version);
            IPicklistItemStateCreated e = NewPicklistItemStateCreated(stateEventId);
            var s = outerState.PicklistItems.Get(c.PicklistItemOrderShipGrpInvId, true);

            e.ItemStatusId = c.ItemStatusId;
            e.Quantity     = c.Quantity;
            e.Active       = c.Active;

            e.CreatedBy = (string)c.RequesterId;
            e.CreatedAt = ApplicationContext.Current.TimestampService.Now <DateTime>();
            return(e);
        }// END Map(ICreate... ////////////////////////////
Exemple #4
0
        protected virtual void Update(IPicklistBinCommand c, Action <IPicklistBinAggregate> action)
        {
            var aggregateId = c.AggregateId;
            var state       = StateRepository.Get(aggregateId, false);
            var aggregate   = GetPicklistBinAggregate(state);

            var eventStoreAggregateId = ToEventStoreAggregateId(aggregateId);

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

            if (repeated)
            {
                return;
            }

            aggregate.ThrowOnInvalidStateTransition(c);
            action(aggregate);
            Persist(eventStoreAggregateId, aggregate, state);
        }
Exemple #5
0
        protected void ThrowOnInconsistentCommands(IPicklistBinCommand command, IPicklistItemCommand innerCommand)
        {
            var properties      = command as ICreateOrMergePatchOrDeletePicklistBin;
            var innerProperties = innerCommand as ICreateOrMergePatchOrRemovePicklistItem;

            if (properties == null || innerProperties == null)
            {
                return;
            }
            if (innerProperties.PicklistBinId == default(string))
            {
                innerProperties.PicklistBinId = properties.PicklistBinId;
            }
            else
            {
                var outerPicklistBinIdName  = "PicklistBinId";
                var outerPicklistBinIdValue = properties.PicklistBinId;
                var innerPicklistBinIdName  = "PicklistBinId";
                var innerPicklistBinIdValue = innerProperties.PicklistBinId;
                ThrowOnInconsistentIds(innerProperties, innerPicklistBinIdName, innerPicklistBinIdValue, outerPicklistBinIdName, outerPicklistBinIdValue);
            }
        }// END ThrowOnInconsistentCommands /////////////////////
Exemple #6
0
        }// END ThrowOnInconsistentCommands /////////////////////

        protected virtual IPicklistItemEvent Map(IPicklistItemCommand c, IPicklistBinCommand outerCommand, long version, IPicklistBinState outerState)
        {
            var create = (c.CommandType == CommandType.Create) ? (c as ICreatePicklistItem) : null;

            if (create != null)
            {
                return(MapCreate(create, outerCommand, version, outerState));
            }

            var merge = (c.CommandType == CommandType.MergePatch || c.CommandType == null) ? (c as IMergePatchPicklistItem) : null;

            if (merge != null)
            {
                return(MapMergePatch(merge, outerCommand, version, outerState));
            }

            var remove = (c.CommandType == CommandType.Remove) ? (c as IRemovePicklistItem) : null;

            if (remove != null)
            {
                return(MapRemove(remove, outerCommand, version));
            }
            throw new NotSupportedException();
        }
Exemple #7
0
 private static bool IsCommandCreate(IPicklistBinCommand c)
 {
     return(c.Version == PicklistBinState.VersionZero);
 }