public void AddTransitStateToNotification(TransitState transitState) { Guard.ArgumentNotNull(() => transitState, transitState); if (TransitStatesCollection.Any(ts => ts.OrdinalPosition == transitState.OrdinalPosition)) { throw new InvalidOperationException( string.Format( "Attempted to add a Transit State at position {0} for TransportRoute {1}. The TransportRoute already has a Transit State at this position.", transitState.OrdinalPosition, Id)); } if (TransitStatesCollection.Count > 0) { var validPositions = GetAvailableTransitStatePositions(); if (!validPositions.Contains(transitState.OrdinalPosition)) { throw new InvalidOperationException( string.Format( "Attempted to add a Transit State at position {0} for TransportRoute {1}. This is not a valid position for a new Transit State.", transitState.OrdinalPosition, Id)); } } TransitStatesCollection.Add(transitState); }
public void AddTransitStateToNotification(TransitState transitState) { Guard.ArgumentNotNull(() => transitState, transitState); if (TransitStatesCollection.Any(ts => ts.CompetentAuthority == transitState.CompetentAuthority)) { throw new InvalidOperationException( string.Format( "Cannot add a Transit State in the same Competent Authority as another in the collection. TransportRoute {0}. Competent authority {1}", Id, transitState.CompetentAuthority.Name)); } if (TransitStatesCollection.Any(ts => ts.EntryPoint.Id == transitState.EntryPoint.Id)) { throw new InvalidOperationException( string.Format( "Cannot add a Transit State with the same entry point as another in the collection. TransportRoute {0}. Entry point {1}.", Id, transitState.EntryPoint.Name)); } if (TransitStatesCollection.Any(ts => ts.ExitPoint.Id == transitState.ExitPoint.Id)) { throw new InvalidOperationException( string.Format( "Cannot add a Transit State with the same exit point as another in the collection. TransportRoute {0}. Exit point {1}.", Id, transitState.ExitPoint.Name)); } if (TransitStatesCollection.Any(ts => ts.OrdinalPosition == transitState.OrdinalPosition)) { throw new InvalidOperationException( string.Format( "Attempted to add a Transit State at position {0} for TransportRoute {1}. The TransportRoute already has a Transit State at this position.", transitState.OrdinalPosition, Id)); } if (TransitStatesCollection.Count > 0) { var validPositions = GetAvailableTransitStatePositions(); if (!validPositions.Contains(transitState.OrdinalPosition)) { throw new InvalidOperationException( string.Format( "Attempted to add a Transit State at position {0} for TransportRoute {1}. This is not a valid position for a new Transit State.", transitState.OrdinalPosition, Id)); } } TransitStatesCollection.Add(transitState); }