コード例 #1
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));
        }
コード例 #2
0
        public void SetStateOfImportForNotification(StateOfImport stateOfImport, ITransportRouteValidator validator)
        {
            Guard.ArgumentNotNull(() => stateOfImport, stateOfImport);
            Guard.ArgumentNotNull(() => validator, validator);

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

            StateOfImport = stateOfImport;
        }