Beispiel #1
0
        }// END ThrowOnInconsistentCommands /////////////////////

        protected virtual IInventoryItemEntryEvent Map(IInventoryItemEntryCommand c, IInventoryItemCommand outerCommand, long version, IInventoryItemState outerState)
        {
            var create = (c.CommandType == CommandType.Create) ? (c as ICreateInventoryItemEntry) : null;

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

            throw new NotSupportedException();
        }
        protected bool IsRepeatedCommand(IInventoryItemCommand command, IEventStoreAggregateId eventStoreAggregateId, IInventoryItemState state)
        {
            bool repeated = false;

            if (((IInventoryItemStateProperties)state).Version > command.AggregateVersion)
            {
                var lastEvent = EventStore.GetEvent(typeof(IInventoryItemEvent), eventStoreAggregateId, command.AggregateVersion);
                if (lastEvent != null && lastEvent.CommandId == command.CommandId)
                {
                    repeated = true;
                }
            }
            return(repeated);
        }
        protected virtual void Update(IInventoryItemCommand c, Action <IInventoryItemAggregate> action)
        {
            var aggregateId = c.AggregateId;
            var state       = StateRepository.Get(aggregateId, false);
            var aggregate   = GetInventoryItemAggregate(state);

            var eventStoreAggregateId = ToEventStoreAggregateId(aggregateId);

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

            if (repeated)
            {
                return;
            }

            aggregate.ThrowOnInvalidStateTransition(c);
            action(aggregate);
            Persist(eventStoreAggregateId, aggregate, state);
        }
Beispiel #4
0
        protected void ThrowOnInconsistentCommands(IInventoryItemCommand command, IInventoryItemEntryCommand innerCommand)
        {
            var properties      = command as ICreateOrMergePatchOrDeleteInventoryItem;
            var innerProperties = innerCommand as ICreateOrMergePatchOrRemoveInventoryItemEntry;

            if (properties == null || innerProperties == null)
            {
                return;
            }
            if (innerProperties.InventoryItemId == default(InventoryItemId))
            {
                innerProperties.InventoryItemId = properties.InventoryItemId;
            }
            else
            {
                var outerInventoryItemIdName  = "InventoryItemId";
                var outerInventoryItemIdValue = properties.InventoryItemId;
                var innerInventoryItemIdName  = "InventoryItemId";
                var innerInventoryItemIdValue = innerProperties.InventoryItemId;
                ThrowOnInconsistentIds(innerProperties, innerInventoryItemIdName, innerInventoryItemIdValue, outerInventoryItemIdName, outerInventoryItemIdValue);
            }
        }// END ThrowOnInconsistentCommands /////////////////////
Beispiel #5
0
 private static bool IsCommandCreate(IInventoryItemCommand c)
 {
     return(c.Version == InventoryItemState.VersionZero);
 }
Beispiel #6
0
        protected virtual IInventoryItemEntryStateCreated MapCreate(ICreateInventoryItemEntry c, IInventoryItemCommand outerCommand, long version, IInventoryItemState outerState)
        {
            c.RequesterId = outerCommand.RequesterId;
            var stateEventId = new InventoryItemEntryEventId(c.InventoryItemId, c.EntrySeqId, version);
            IInventoryItemEntryStateCreated e = NewInventoryItemEntryStateCreated(stateEventId);
            var s = outerState.Entries.Get(c.EntrySeqId, true);

            e.OnHandQuantity    = c.OnHandQuantity;
            e.InTransitQuantity = c.InTransitQuantity;
            e.ReservedQuantity  = c.ReservedQuantity;
            e.OccupiedQuantity  = c.OccupiedQuantity;
            e.VirtualQuantity   = c.VirtualQuantity;
            e.Source            = c.Source;
            e.OccurredAt        = c.OccurredAt;

            e.CreatedBy = (string)c.RequesterId;
            e.CreatedAt = ApplicationContext.Current.TimestampService.Now <DateTime>();
            return(e);
        }// END Map(ICreate... ////////////////////////////