예제 #1
0
        /// <summary>
        /// Sets the value.
        /// </summary>
        /// <param name="location">The location.</param>
        public void SetValue(Rock.Model.Location location)
        {
            if (location != null)
            {
                ItemId = location.Id.ToString();
                List <int> parentLocationIds = new List <int>();
                var        parentLocation    = location.ParentLocation;

                while (parentLocation != null)
                {
                    if (parentLocationIds.Contains(parentLocation.Id))
                    {
                        // infinite recursion
                        break;
                    }

                    parentLocationIds.Insert(0, parentLocation.Id);;
                    parentLocation = parentLocation.ParentLocation;
                }

                InitialItemParentIds = parentLocationIds.AsDelimited(",");
                ItemName             = location.ToString();
            }
            else
            {
                ItemId   = Constants.None.IdValue;
                ItemName = Constants.None.TextHtml;
            }
        }
예제 #2
0
 public ImpactLocation(Rock.Model.Location location)
 {
     Street1 = location.Street1;
     Street2 = location.Street2;
     City    = location.City;
     State   = location.State;
     Zip     = location.Zip;
 }
예제 #3
0
 public ImpactLocation(Rock.Model.Location location)
 {
     Street1    = location.Street1;
     Street2    = location.Street2;
     City       = location.City;
     State      = location.State;
     PostalCode = location.PostalCode;
     Country    = location.Country;
 }
예제 #4
0
 public void SetValue(Rock.Model.Location location)
 {
     if (location != null)
     {
         SetValueFromNamedLocation(NamedLocationCache.Get(location));
     }
     else
     {
         SetValueFromNamedLocation(( NamedLocationCache )null);
     }
 }
예제 #5
0
        /// <summary>
        /// Gets the values.
        /// </summary>
        /// <param name="location">The location.</param>
        public void GetValues(Rock.Model.Location location)
        {
            if (location == null)
            {
                return;
            }

            if (this.HasValue)
            {
                // Get field values, nullifying any fields that are not available for the selected country.
                var street1    = GetLocationFieldValue(this.Street1, _AddressLine1Requirement);
                var street2    = GetLocationFieldValue(this.Street2, _AddressLine2Requirement);
                var city       = GetLocationFieldValue(this.City, _CityRequirement);
                var county     = GetLocationFieldValue(this.County, _LocalityRequirement);
                var state      = GetLocationFieldValue(this.State, _StateRequirement);
                var postalCode = GetLocationFieldValue(this.PostalCode, _PostalCodeRequirement);

                // If country selection is available, get the selected value otherwise use the system default.
                if (_ShowCountrySelection)
                {
                    location.Country = _ddlCountry.SelectedValue;
                }
                else
                {
                    location.Country = GetDefaultCountry();
                }

                location.Street1    = street1;
                location.Street2    = street2;
                location.City       = city;
                location.County     = county;
                location.State      = state;
                location.PostalCode = postalCode;
            }
            else
            {
                // No non-default values have been entered, so return an empty location.
                location.Country    = null;
                location.Street1    = null;
                location.Street2    = null;
                location.City       = null;
                location.County     = null;
                location.State      = null;
                location.PostalCode = null;
            }
        }
예제 #6
0
            /// <summary>
            /// Initializes a new instance of the <see cref="CampusLocation"/> class.
            /// </summary>
            /// <param name="locationModel">The location model.</param>
            public CampusLocation(Rock.Model.Location locationModel)
            {
                if (locationModel != null)
                {
                    Street1    = locationModel.Street1;
                    Street2    = locationModel.Street2;
                    City       = locationModel.City;
                    State      = locationModel.State;
                    PostalCode = locationModel.PostalCode;
                    Country    = locationModel.Country;

                    if (locationModel.GeoPoint != null)
                    {
                        Latitude  = locationModel.GeoPoint.Latitude;
                        Longitude = locationModel.GeoPoint.Longitude;
                    }
                }
            }
예제 #7
0
 /// <summary>
 /// Sets the values. Use SetValues(null) to set defaults.
 /// </summary>
 /// <param name="location">The location.</param>
 public void SetValues(Rock.Model.Location location)
 {
     if (location != null)
     {
         Country    = location.Country;
         Street1    = location.Street1;
         Street2    = location.Street2;
         City       = location.City;
         County     = location.County;
         State      = location.State;
         PostalCode = location.PostalCode;
     }
     else
     {
         Country    = GetDefaultCountry();
         Street1    = string.Empty;
         Street2    = string.Empty;
         City       = string.Empty;
         County     = string.Empty;
         State      = GetDefaultState();
         PostalCode = string.Empty;
     }
 }
예제 #8
0
        /// <summary>
        /// Sets the value.
        /// </summary>
        /// <param name="location">The location.</param>
        public void SetValue(Rock.Model.Location location)
        {
            if (location != null)
            {
                ItemId = location.Id.ToString();

                string parentLocationIds = string.Empty;
                var    parentLocation    = location.ParentLocation;
                while (parentLocation != null)
                {
                    parentLocationIds = parentLocation.Id + "," + parentLocationIds;
                    parentLocation    = parentLocation.ParentLocation;
                }

                InitialItemParentIds = parentLocationIds.TrimEnd(new char[] { ',' });
                ItemName             = location.ToString();
            }
            else
            {
                ItemId   = Constants.None.IdValue;
                ItemName = Constants.None.TextHtml;
            }
        }
예제 #9
0
        /// <summary>
        /// Standardizes and Geocodes an address using Smarty Streets service
        /// </summary>
        /// <param name="location">The location.</param>
        /// <param name="resultMsg">The result MSG.</param>
        /// <returns>
        /// True/False value of whether the verification was successful or not
        /// </returns>
        public override VerificationResult Verify(Rock.Model.Location location, out string resultMsg)
        {
            VerificationResult result = VerificationResult.None;

            resultMsg = string.Empty;

            SmartyStreetsAPIKey apiKey = GetAPIKey();

            var dpvCodes   = GetAttributeValue("AcceptableDPVCodes").SplitDelimitedValues();
            var precisions = GetAttributeValue("AcceptablePrecisions").SplitDelimitedValues();

            var payload = new[] { new { addressee = location.Name, street = location.Street1, street2 = location.Street2, city = location.City, state = location.State, zipcode = location.PostalCode, candidates = 1 } };

            var client  = new RestClient(string.Format("https://api.smartystreets.com/street-address?auth-id={0}&auth-token={1}", apiKey.AuthID, apiKey.AuthToken));
            var request = new RestRequest(Method.POST);

            request.RequestFormat = DataFormat.Json;
            request.AddHeader("Accept", "application/json");
            request.AddBody(payload);
            var response = client.Execute(request);

            if (response.StatusCode == HttpStatusCode.OK)
            {
                var candidates = JsonConvert.DeserializeObject(response.Content, typeof(List <CandidateAddress>)) as List <CandidateAddress>;
                if (candidates.Any())
                {
                    var candidate = candidates.FirstOrDefault();
                    resultMsg = string.Format("RecordType:{0}; DPV MatchCode:{1}; Precision:{2}",
                                              candidate.metadata.record_type, candidate.analysis.dpv_match_code, candidate.metadata.precision);

                    location.StandardizeAttemptedResult = candidate.analysis.dpv_match_code;
                    if (dpvCodes.Contains(candidate.analysis.dpv_match_code))
                    {
                        location.Street1    = candidate.delivery_line_1;
                        location.Street2    = candidate.delivery_line_2;
                        location.City       = candidate.components.city_name;
                        location.County     = candidate.metadata.county_name;
                        location.State      = candidate.components.state_abbreviation;
                        location.PostalCode = candidate.components.zipcode + "-" + candidate.components.plus4_code;
                        location.Barcode    = candidate.delivery_point_barcode;
                        result = result | VerificationResult.Standardized;
                    }

                    location.GeocodeAttemptedResult = candidate.metadata.precision;
                    if (precisions.Contains(candidate.metadata.precision))
                    {
                        if (location.SetLocationPointFromLatLong(candidate.metadata.latitude, candidate.metadata.longitude))
                        {
                            result = result | VerificationResult.Geocoded;
                        }
                    }
                }
                else
                {
                    resultMsg = "No Match";
                }
            }
            else
            {
                result    = VerificationResult.ConnectionError;
                resultMsg = response.StatusDescription;
            }

            return(result);
        }