Inheritance: System.Entity, IState, IExitPoint
Ejemplo n.º 1
0
        public void SetStateOfExportForNotification(StateOfExport stateOfExport)
        {
            Guard.ArgumentNotNull(() => stateOfExport, stateOfExport);

            if (StateOfImport != null && StateOfImport.Country.Id == stateOfExport.Country.Id)
            {
                throw new InvalidOperationException(
                    string.Format(
                        "Cannot add a State of Export in the same country as the State of Import for TransportRoute {0}. Country: {1}",
                        Id,
                        StateOfExport.Country.Name));
            }

            if (TransitStatesCollection != null &&
                TransitStatesCollection.Select(ts => ts.Country.Id).Contains(stateOfExport.Country.Id))
            {
                throw new InvalidOperationException(
                    string.Format(
                        "Cannot add a State of Export in the same country as a Transit State for TransportRoute {0}. Country: {1}",
                        Id,
                        stateOfExport.Country.Name));
            }

            StateOfExport = stateOfExport;
        }
Ejemplo n.º 2
0
        public void SetStateOfExportForNotification(StateOfExport stateOfExport, ITransportRouteValidator validator)
        {
            Guard.ArgumentNotNull(() => stateOfExport, stateOfExport);
            Guard.ArgumentNotNull(() => validator, validator);

            if (!validator.IsImportAndExportStatesCombinationValid(StateOfImport, stateOfExport))
            {
                throw new InvalidOperationException(
                          string.Format(
                              "Cannot add a State of Export in the same country as the State of Import for TransportRoute {0}. Country: {1}",
                              Id,
                              stateOfExport.Country.Name));
            }

            StateOfExport = stateOfExport;
        }
Ejemplo n.º 3
0
        public bool IsImportAndExportStatesCombinationValid(StateOfImport importState, StateOfExport exportState)
        {
            // Are both defined
            if (exportState == null || importState == null)
            {
                return(true);
            }

            // are both same country?
            if (exportState.Country.Id != importState.Country.Id)
            {
                return(true);
            }

            // Is UK authority? If not then we do not allow
            var unitedKingdomExportAuth = uksCompetentAuthorities.FirstOrDefault(uka => exportState.CompetentAuthority.Id == uka.CompetentAuthority.Id);

            if (unitedKingdomExportAuth == null)
            {
                return(false);
            }

            // Now check if it is an allowed combination
            return(allowedCombinations.Where(ac => ac.ExportCompetentAuthority == unitedKingdomExportAuth.AsCompetentAuthority())
                   .Any(ac => ac.ImportCompetentAuthorityId == importState.CompetentAuthority.Id));
        }