protected void ThrowOnWrongEvent(ISellableInventoryItemEvent e) { var id = new System.Text.StringBuilder(); id.Append("[").Append("SellableInventoryItem|"); var stateEntityId = this.SellableInventoryItemId; // Aggregate Id var eventEntityId = e.SellableInventoryItemEventId.SellableInventoryItemId; if (stateEntityId != eventEntityId) { throw DomainError.Named("mutateWrongEntity", "Entity Id {0} in state but entity id {1} in event", stateEntityId, eventEntityId); } id.Append(stateEntityId).Append(","); id.Append("]"); var stateVersion = this.Version; var eventVersion = e.SellableInventoryItemEventId.Version; if (stateVersion != eventVersion) { throw OptimisticConcurrencyException.Create(stateVersion, eventVersion, id.ToString()); } }
public static void ThrowOnInconsistentEventIds(ISellableInventoryItemEvent oe, ISellableInventoryItemEntryEvent e) { if (!oe.SellableInventoryItemEventId.SellableInventoryItemId.Equals(e.SellableInventoryItemEntryEventId.SellableInventoryItemId)) { throw DomainError.Named("inconsistentEventIds", "Outer Id SellableInventoryItemId {0} but inner id SellableInventoryItemId {1}", oe.SellableInventoryItemEventId.SellableInventoryItemId, e.SellableInventoryItemEntryEventId.SellableInventoryItemId); } }
public virtual SellableInventoryItemStateCreatedOrMergePatchedOrDeletedDto ToSellableInventoryItemStateEventDto(ISellableInventoryItemEvent stateEvent) { if (stateEvent.EventType == StateEventType.Created) { var e = (ISellableInventoryItemStateCreated)stateEvent; return(ToSellableInventoryItemStateCreatedDto(e)); } else if (stateEvent.EventType == StateEventType.MergePatched) { var e = (ISellableInventoryItemStateMergePatched)stateEvent; return(ToSellableInventoryItemStateMergePatchedDto(e)); } throw DomainError.Named("invalidEventType", String.Format("Invalid state event type: {0}", stateEvent.EventType)); }
public void AddSellableInventoryItemEvent(ISellableInventoryItemEvent e) { _innerStateEvents.Add((SellableInventoryItemStateCreatedOrMergePatchedOrDeletedDto)e); }