コード例 #1
0
        /// <summary>
        /// Applies the city id to the address if the city is listed in the system
        /// and has a matching state and country id compared to what was supplied.
        /// </summary>
        /// <param name="address"></param>
        /// <param name="stateLookup"></param>
        /// <param name="errors">list of errors to populate if any validation fails.</param>
        public static bool ApplyState(Address address, StateLookUp stateLookup, IList <string> errors)
        {
            if (address.StateId == LocationConstants.StateId_NA_Online)
            {
                return(true);
            }
            if (address.StateId > 0)
            {
                return(true);
            }

            // Can't determine state by name if it's not supplied.
            if (string.IsNullOrEmpty(address.State))
            {
                return(false);
            }

            int initialErrorCount = errors.Count;

            // Check the state.
            bool  isCountryIdEmpty = (address.CountryId <= 0);
            State state            = isCountryIdEmpty ? stateLookup[address.State] : stateLookup.FindByCountry(address.State, address.CountryId);

            if (ValidationUtils.Validate(state == null, errors, "Invalid state supplied."))
            {
                address.StateId   = state.Id;
                address.StateAbbr = state.Abbreviation;
                address.State     = state.Name;
            }

            return(initialErrorCount == errors.Count);
        }
コード例 #2
0
        private void CheckCountryStateNames()
        {
            // Check to see if country name is supplied instead of the id.
            if (_countryId <= 0 && !string.IsNullOrEmpty(_country))
            {
                Country country = _countryLookup[_country];
                if (country != null)
                {
                    _countryId = country.RealId;
                }
            }

            // Check to see if the state name was supplied instead of the state id.
            if (_stateId <= 0 && !string.IsNullOrEmpty(_state))
            {
                State state = _stateLookup.FindByCountry(_state, _countryId);
                if (state != null)
                {
                    _stateId = state.Id;
                }
            }
        }