Exemplo n.º 1
0
        public TransitState(Country country, CompetentAuthority competentAuthority, EntryOrExitPoint entryPoint, EntryOrExitPoint exitPoint, int ordinalPosition)
        {
            Guard.ArgumentNotNull(() => country, country);
            Guard.ArgumentNotNull(() => competentAuthority, competentAuthority);
            Guard.ArgumentNotNull(() => entryPoint, entryPoint);
            Guard.ArgumentNotNull(() => exitPoint, exitPoint);
            Guard.ArgumentNotZeroOrNegative(() => OrdinalPosition, ordinalPosition);

            if (country.Id != competentAuthority.Country.Id ||
                country.Id != entryPoint.Country.Id ||
                country.Id != exitPoint.Country.Id)
            {
                throw new InvalidOperationException(string.Format("Transit State Competent Authority, Entry and Exit Point must all have the same country. Competent Authority: {0}. Entry: {1}. Exit: {2}. Country: {3}",
                                                                  competentAuthority.Id,
                                                                  entryPoint.Id,
                                                                  exitPoint.Id,
                                                                  country.Name));
            }

            Country            = country;
            CompetentAuthority = competentAuthority;
            ExitPoint          = exitPoint;
            EntryPoint         = entryPoint;
            OrdinalPosition    = ordinalPosition;
        }
Exemplo n.º 2
0
        public TransitState(Country country, CompetentAuthority competentAuthority, EntryOrExitPoint entryPoint, EntryOrExitPoint exitPoint, int ordinalPosition)
        {
            Guard.ArgumentNotNull(() => country, country);
            Guard.ArgumentNotNull(() => competentAuthority, competentAuthority);
            Guard.ArgumentNotNull(() => entryPoint, entryPoint);
            Guard.ArgumentNotNull(() => exitPoint, exitPoint);
            Guard.ArgumentNotZeroOrNegative(() => OrdinalPosition, ordinalPosition);

            if (country.Id != competentAuthority.Country.Id 
                || country.Id != entryPoint.Country.Id
                || country.Id != exitPoint.Country.Id)
            {
                throw new InvalidOperationException(string.Format("Transit State Competent Authority, Entry and Exit Point must all have the same country. Competent Authority: {0}. Entry: {1}. Exit: {2}. Country: {3}",
                    competentAuthority.Id,
                    entryPoint.Id,
                    exitPoint.Id,
                    country.Name));
            }

            Country = country;
            CompetentAuthority = competentAuthority;
            ExitPoint = exitPoint;
            EntryPoint = entryPoint;
            OrdinalPosition = ordinalPosition;
        }
Exemplo n.º 3
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);
        }
Exemplo n.º 4
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);
        }
Exemplo n.º 5
0
        internal void UpdateTransitState(Country country,
                                         CompetentAuthority competentAuthority,
                                         EntryOrExitPoint entryPoint,
                                         EntryOrExitPoint exitPoint,
                                         int?ordinalPosition)
        {
            Guard.ArgumentNotNull(() => country, country);
            Guard.ArgumentNotNull(() => competentAuthority, competentAuthority);
            Guard.ArgumentNotNull(() => entryPoint, entryPoint);
            Guard.ArgumentNotNull(() => exitPoint, exitPoint);

            this.CompetentAuthority = competentAuthority;
            this.Country            = country;
            this.EntryPoint         = entryPoint;
            this.ExitPoint          = exitPoint;
            this.OrdinalPosition    = ordinalPosition ?? this.OrdinalPosition;
        }
Exemplo n.º 6
0
        internal void UpdateTransitState(Country country, 
            CompetentAuthority competentAuthority, 
            EntryOrExitPoint entryPoint,
            EntryOrExitPoint exitPoint, 
            int? ordinalPosition)
        {
            Guard.ArgumentNotNull(() => country, country);
            Guard.ArgumentNotNull(() => competentAuthority, competentAuthority);
            Guard.ArgumentNotNull(() => entryPoint, entryPoint);
            Guard.ArgumentNotNull(() => exitPoint, exitPoint);

            this.CompetentAuthority = competentAuthority;
            this.Country = country;
            this.EntryPoint = entryPoint;
            this.ExitPoint = exitPoint;
            this.OrdinalPosition = ordinalPosition ?? this.OrdinalPosition;
        }
Exemplo n.º 7
0
        public void Update(Country country, CompetentAuthority competentAuthority, EntryOrExitPoint exitPoint)
        {
            Guard.ArgumentNotNull(() => country, country);
            Guard.ArgumentNotNull(() => competentAuthority, competentAuthority);
            Guard.ArgumentNotNull(() => exitPoint, exitPoint);

            if (country.Id != competentAuthority.Country.Id || country.Id != exitPoint.Country.Id)
            {
                var message =
                    string.Format(
                        @"The country of the export state must be the same as the competent authority country and exit point country.
                                Country: {0} Competent Authority: {1} Exit Point: {2}", country.Id, competentAuthority.Country.Id, exitPoint.Country.Id);
                throw new InvalidOperationException(message);
            }

            Country            = country;
            CompetentAuthority = competentAuthority;
            ExitPoint          = exitPoint;
        }
Exemplo n.º 8
0
        public void Update(Country country, CompetentAuthority competentAuthority, EntryOrExitPoint exitPoint)
        {
            Guard.ArgumentNotNull(() => country, country);
            Guard.ArgumentNotNull(() => competentAuthority, competentAuthority);
            Guard.ArgumentNotNull(() => exitPoint, exitPoint);

            if (country.Id != competentAuthority.Country.Id || country.Id != exitPoint.Country.Id)
            {
                var message =
                    string.Format(
                        @"The country of the export state must be the same as the competent authority country and exit point country.
                                Country: {0} Competent Authority: {1} Exit Point: {2}", country.Id, competentAuthority.Country.Id, exitPoint.Country.Id);
                throw new InvalidOperationException(message);
            }

            Country = country;
            CompetentAuthority = competentAuthority;
            ExitPoint = exitPoint;
        }
Exemplo n.º 9
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 (allTransitStatesExceptTarget.Any(ts => ts.Country.Id == country.Id))
            {
                throw new InvalidOperationException(
                    string.Format(
                        "Cannot edit a Transit State to put it in the same Country as another in the collection. TransportRoute {0}. Country {1}",
                        Id,
                        country.Name));
            }

            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);

            CheckAllTransitStatesInEU();
        }