public virtual void When(IInventoryItemRequirementStateMergePatched e)
        {
            ThrowOnWrongEvent(e);

            if (e.Quantity == null)
            {
                if (e.IsPropertyQuantityRemoved)
                {
                    this.Quantity = default(decimal);
                }
            }
            else
            {
                this.Quantity = (e.Quantity != null && e.Quantity.HasValue) ? e.Quantity.Value : default(decimal);
            }


            this.UpdatedBy = e.CreatedBy;
            this.UpdatedAt = e.CreatedAt;


            foreach (IInventoryItemRequirementEntryEvent innerEvent in e.InventoryItemRequirementEntryEvents)
            {
                IInventoryItemRequirementEntryState innerState = this.Entries.Get(innerEvent.GlobalId.EntrySeqId);

                innerState.Mutate(innerEvent);
            }
        }
Example #2
0
        protected virtual IInventoryItemRequirementStateMergePatched Map(IMergePatchInventoryItemRequirement c)
        {
            var stateEventId = new InventoryItemRequirementEventId(c.InventoryItemRequirementId, c.Version);
            IInventoryItemRequirementStateMergePatched e = NewInventoryItemRequirementStateMergePatched(stateEventId);


            e.CommandId = c.CommandId;


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

            var version = c.Version;

            decimal quantity = _state.Quantity;

            foreach (IInventoryItemRequirementEntryCommand innerCommand in c.InventoryItemRequirementEntryCommands)
            {
                ThrowOnInconsistentCommands(c, innerCommand);

                IInventoryItemRequirementEntryEvent innerEvent = Map(innerCommand, c, version, _state);
                e.AddInventoryItemRequirementEntryEvent(innerEvent);
                // ////////////////
                if (!(innerEvent is IInventoryItemRequirementEntryStateCreated))
                {
                    continue;
                }
                var entryCreated = (IInventoryItemRequirementEntryStateCreated)innerEvent;
                quantity = quantity + (entryCreated.Quantity != null ? entryCreated.Quantity.GetValueOrDefault() : default(decimal));
                // ////////////////
            }

            e.Quantity = quantity;

            return(e);
        }
Example #3
0
        public virtual void MergePatch(IMergePatchInventoryItemRequirement c)
        {
            IInventoryItemRequirementStateMergePatched e = Map(c);

            Apply(e);
        }
Example #4
0
        public virtual InventoryItemRequirementStateMergePatchedDto ToInventoryItemRequirementStateMergePatchedDto(IInventoryItemRequirementStateMergePatched e)
        {
            var dto = new InventoryItemRequirementStateMergePatchedDto();

            dto.InventoryItemRequirementEventId = e.InventoryItemRequirementEventId;
            dto.CreatedAt = e.CreatedAt;
            dto.CreatedBy = e.CreatedBy;
            dto.CommandId = e.CommandId;
            dto.Quantity  = e.Quantity;
            dto.IsPropertyQuantityRemoved = e.IsPropertyQuantityRemoved;
            var inventoryItemRequirementEntryEvents = new List <InventoryItemRequirementEntryStateCreatedOrMergePatchedOrRemovedDto>();

            foreach (var ee in e.InventoryItemRequirementEntryEvents)
            {
                InventoryItemRequirementEntryStateCreatedOrMergePatchedOrRemovedDto eeDto = InventoryItemRequirementEntryStateEventDtoConverter.ToInventoryItemRequirementEntryStateEventDto(ee);
                inventoryItemRequirementEntryEvents.Add(eeDto);
            }
            dto.InventoryItemRequirementEntryEvents = inventoryItemRequirementEntryEvents.ToArray();


            return(dto);
        }
Example #5
0
 void IInventoryItemRequirementState.When(IInventoryItemRequirementStateMergePatched e)
 {
     throw new NotSupportedException();
 }