Exemplo n.º 1
0
 public static void ThrowOnInconsistentEventIds(IOrderEvent oe, IOrderItemEvent e)
 {
     if (!oe.OrderEventId.OrderId.Equals(e.OrderItemEventId.OrderId))
     {
         throw DomainError.Named("inconsistentEventIds", "Outer Id OrderId {0} but inner id OrderId {1}",
                                 oe.OrderEventId.OrderId, e.OrderItemEventId.OrderId);
     }
 }
Exemplo n.º 2
0
        public void Save(IOrderItemEvent stateEvent)
        {
            CurrentSession.Save(stateEvent);
            var saveable = stateEvent as ISaveable;

            if (saveable != null)
            {
                saveable.Save();
            }
        }
Exemplo n.º 3
0
        protected void ThrowOnWrongEvent(IOrderItemEvent e)
        {
            var id = new System.Text.StringBuilder();

            id.Append("[").Append("OrderItem|");

            var stateEntityIdOrderId = (this as IGlobalIdentity <OrderItemId>).GlobalId.OrderId;
            var eventEntityIdOrderId = e.OrderItemEventId.OrderId;

            if (stateEntityIdOrderId != eventEntityIdOrderId)
            {
                throw DomainError.Named("mutateWrongEntity", "Entity Id OrderId {0} in state but entity id OrderId {1} in event", stateEntityIdOrderId, eventEntityIdOrderId);
            }
            id.Append(stateEntityIdOrderId).Append(",");

            var stateEntityIdOrderItemSeqId = (this as IGlobalIdentity <OrderItemId>).GlobalId.OrderItemSeqId;
            var eventEntityIdOrderItemSeqId = e.OrderItemEventId.OrderItemSeqId;

            if (stateEntityIdOrderItemSeqId != eventEntityIdOrderItemSeqId)
            {
                throw DomainError.Named("mutateWrongEntity", "Entity Id OrderItemSeqId {0} in state but entity id OrderItemSeqId {1} in event", stateEntityIdOrderItemSeqId, eventEntityIdOrderItemSeqId);
            }
            id.Append(stateEntityIdOrderItemSeqId).Append(",");

            id.Append("]");

            if (ForReapplying)
            {
                return;
            }
            var stateVersion = this.Version;
            var stateEvent   = e is IOrderItemStateEvent ? (IOrderItemStateEvent)e : null;

            if (e == null)
            {
                return;
            }
            stateEvent.Version = stateVersion;
            //var stateEventStateVersion = stateEvent.Version;
            //if (OrderItemState.VersionZero == stateEventStateVersion)
            //{
            //    stateEventStateVersion = stateEvent.Version = stateVersion;
            //}
            //if (stateVersion != stateEventStateVersion)
            //{
            //    throw OptimisticConcurrencyException.Create(stateVersion, stateEventStateVersion, id.ToString());
            //}
        }
Exemplo n.º 4
0
 void IOrderStateMergePatched.AddOrderItemEvent(IOrderItemEvent e)
 {
     this._orderItemEvents.AddOrderItemEvent(e);
 }
Exemplo n.º 5
0
        protected virtual IOrderStateMergePatched Map(IMergePatchOrder c)
        {
            var stateEventId          = new OrderEventId(c.OrderId, c.Version);
            IOrderStateMergePatched e = NewOrderStateMergePatched(stateEventId);

            e.OrderTypeId             = c.OrderTypeId;
            e.OrderName               = c.OrderName;
            e.ExternalId              = c.ExternalId;
            e.SalesChannelEnumId      = c.SalesChannelEnumId;
            e.OrderDate               = c.OrderDate;
            e.Priority                = c.Priority;
            e.EntryDate               = c.EntryDate;
            e.PickSheetPrintedDate    = c.PickSheetPrintedDate;
            e.StatusId                = c.StatusId;
            e.CurrencyUomId           = c.CurrencyUomId;
            e.SyncStatusId            = c.SyncStatusId;
            e.BillingAccountId        = c.BillingAccountId;
            e.OriginFacilityId        = c.OriginFacilityId;
            e.WebSiteId               = c.WebSiteId;
            e.ProductStoreId          = c.ProductStoreId;
            e.TerminalId              = c.TerminalId;
            e.TransactionId           = c.TransactionId;
            e.AutoOrderShoppingListId = c.AutoOrderShoppingListId;
            e.NeedsInventoryIssuance  = c.NeedsInventoryIssuance;
            e.IsRushOrder             = c.IsRushOrder;
            e.InternalCode            = c.InternalCode;
            e.RemainingSubTotal       = c.RemainingSubTotal;
            e.GrandTotal              = c.GrandTotal;
            e.InvoicePerShipment      = c.InvoicePerShipment;
            e.Active = c.Active;
            e.IsPropertyOrderTypeIdRemoved             = c.IsPropertyOrderTypeIdRemoved;
            e.IsPropertyOrderNameRemoved               = c.IsPropertyOrderNameRemoved;
            e.IsPropertyExternalIdRemoved              = c.IsPropertyExternalIdRemoved;
            e.IsPropertySalesChannelEnumIdRemoved      = c.IsPropertySalesChannelEnumIdRemoved;
            e.IsPropertyOrderDateRemoved               = c.IsPropertyOrderDateRemoved;
            e.IsPropertyPriorityRemoved                = c.IsPropertyPriorityRemoved;
            e.IsPropertyEntryDateRemoved               = c.IsPropertyEntryDateRemoved;
            e.IsPropertyPickSheetPrintedDateRemoved    = c.IsPropertyPickSheetPrintedDateRemoved;
            e.IsPropertyStatusIdRemoved                = c.IsPropertyStatusIdRemoved;
            e.IsPropertyCurrencyUomIdRemoved           = c.IsPropertyCurrencyUomIdRemoved;
            e.IsPropertySyncStatusIdRemoved            = c.IsPropertySyncStatusIdRemoved;
            e.IsPropertyBillingAccountIdRemoved        = c.IsPropertyBillingAccountIdRemoved;
            e.IsPropertyOriginFacilityIdRemoved        = c.IsPropertyOriginFacilityIdRemoved;
            e.IsPropertyWebSiteIdRemoved               = c.IsPropertyWebSiteIdRemoved;
            e.IsPropertyProductStoreIdRemoved          = c.IsPropertyProductStoreIdRemoved;
            e.IsPropertyTerminalIdRemoved              = c.IsPropertyTerminalIdRemoved;
            e.IsPropertyTransactionIdRemoved           = c.IsPropertyTransactionIdRemoved;
            e.IsPropertyAutoOrderShoppingListIdRemoved = c.IsPropertyAutoOrderShoppingListIdRemoved;
            e.IsPropertyNeedsInventoryIssuanceRemoved  = c.IsPropertyNeedsInventoryIssuanceRemoved;
            e.IsPropertyIsRushOrderRemoved             = c.IsPropertyIsRushOrderRemoved;
            e.IsPropertyInternalCodeRemoved            = c.IsPropertyInternalCodeRemoved;
            e.IsPropertyRemainingSubTotalRemoved       = c.IsPropertyRemainingSubTotalRemoved;
            e.IsPropertyGrandTotalRemoved              = c.IsPropertyGrandTotalRemoved;
            e.IsPropertyInvoicePerShipmentRemoved      = c.IsPropertyInvoicePerShipmentRemoved;
            e.IsPropertyActiveRemoved = c.IsPropertyActiveRemoved;

            e.CommandId = c.CommandId;


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

            var version = c.Version;

            foreach (IOrderRoleCommand innerCommand in c.OrderRoleCommands)
            {
                ThrowOnInconsistentCommands(c, innerCommand);

                IOrderRoleEvent innerEvent = Map(innerCommand, c, version, _state);
                e.AddOrderRoleEvent(innerEvent);
            }

            foreach (IOrderItemCommand innerCommand in c.OrderItemCommands)
            {
                ThrowOnInconsistentCommands(c, innerCommand);

                IOrderItemEvent innerEvent = Map(innerCommand, c, version, _state);
                e.AddOrderItemEvent(innerEvent);
            }

            foreach (IOrderShipGroupCommand innerCommand in c.OrderShipGroupCommands)
            {
                ThrowOnInconsistentCommands(c, innerCommand);

                IOrderShipGroupEvent innerEvent = Map(innerCommand, c, version, _state);
                e.AddOrderShipGroupEvent(innerEvent);
            }


            return(e);
        }
Exemplo n.º 6
0
 public virtual void AddOrderItemEvent(IOrderItemEvent e)
 {
     ThrowOnInconsistentEventIds(e);
     this._orderItemEvents[e.OrderItemEventId] = e;
 }
Exemplo n.º 7
0
 protected void ThrowOnInconsistentEventIds(IOrderItemEvent e)
 {
     ThrowOnInconsistentEventIds(this, e);
 }
 public virtual OrderItemStateCreatedOrMergePatchedOrRemovedDto ToOrderItemStateEventDto(IOrderItemEvent stateEvent)
 {
     if (stateEvent.EventType == StateEventType.Created)
     {
         var e = (IOrderItemStateCreated)stateEvent;
         return(ToOrderItemStateCreatedDto(e));
     }
     else if (stateEvent.EventType == StateEventType.MergePatched)
     {
         var e = (IOrderItemStateMergePatched)stateEvent;
         return(ToOrderItemStateMergePatchedDto(e));
     }
     throw DomainError.Named("invalidEventType", String.Format("Invalid state event type: {0}", stateEvent.EventType));
 }
Exemplo n.º 9
0
 public void AddOrderItemEvent(IOrderItemEvent e)
 {
     _innerStateEvents.Add((OrderItemStateCreatedOrMergePatchedOrRemovedDto)e);
 }