Example #1
0
        public void UpdateTransitStateForNotification(Guid targetTransitStateId, Country country,
                                                      CompetentAuthority competentAuthority,
                                                      EntryOrExitPoint entryPoint,
                                                      EntryOrExitPoint exitPoint,
                                                      int?ordinalPosition)
        {
            var targetTransitState = TransitStatesCollection.Single(ts => ts.Id == targetTransitStateId);

            if (ordinalPosition.HasValue && ordinalPosition < 1)
            {
                ordinalPosition = null;
            }

            var allTransitStatesExceptTarget =
                TransitStatesCollection.Where(ts => ts.Id != targetTransitStateId).ToArray();

            if (ordinalPosition.HasValue &&
                allTransitStatesExceptTarget.Any(ts => ts.OrdinalPosition == ordinalPosition))
            {
                throw new InvalidOperationException(
                          string.Format(
                              "Attempted to edit a Transit State {0} to position {1} for TransportRoute {2}. The TransportRoute already has another Transit State at this position.",
                              targetTransitStateId,
                              ordinalPosition.Value,
                              Id));
            }

            targetTransitState.UpdateTransitState(country, competentAuthority, entryPoint, exitPoint, ordinalPosition);
        }
Example #2
0
        public void UpdateTransitStateEntryOrExitPoint(Guid targetTransitStateId,
                                                       EntryOrExitPoint entryPoint,
                                                       EntryOrExitPoint exitPoint)
        {
            var targetTransitState = TransitStatesCollection.Single(ts => ts.Id == targetTransitStateId);

            targetTransitState.UpdateTransitState(targetTransitState.Country, targetTransitState.CompetentAuthority,
                                                  entryPoint, exitPoint, targetTransitState.OrdinalPosition);
        }
Example #3
0
        public void RemoveTransitState(Guid id)
        {
            var transitState = TransitStatesCollection.Single(ts => ts.Id == id);

            var removedPosition = transitState.OrdinalPosition;

            TransitStatesCollection.Remove(transitState);

            // Down-shift all transit states above the removed item.
            foreach (var state in TransitStatesCollection.Where(ts => ts.OrdinalPosition > removedPosition))
            {
                state.UpdateOrdinalPosition(state.OrdinalPosition - 1);
            }
        }