/// <summary> /// Geocodes the specified address. /// </summary> /// <param name="address">The address.</param> /// <param name="result">The ServiceObjects result.</param> /// <returns> /// True/False value of whether the address was standardized succesfully /// </returns> public override bool Geocode(Rock.CRM.Address address, out string result) { if (address != null) { string licenseKey = AttributeValue("LicenseKey"); var client = new DOTSGeoCoderSoapClient(); Location_V3 location = client.GetBestMatch_V3( string.Format("{0} {1}", address.Street1, address.Street2), address.City, address.State, address.Zip, licenseKey); result = location.Level; if (location.Level == "S" || location.Level == "P") { address.Latitude = double.Parse(location.Latitude); address.Longitude = double.Parse(location.Longitude); return(true); } } else { result = "Null Address"; } return(false); }
public Rock.CRM.DTO.Address ApiGeocode(string apiKey, Rock.CRM.DTO.Address address) { using (new Rock.Data.UnitOfWorkScope()) { Rock.CMS.UserService userService = new Rock.CMS.UserService(); Rock.CMS.User user = userService.Queryable().Where(u => u.ApiKey == apiKey).FirstOrDefault(); if (user != null) { if (address != null) { Rock.CRM.AddressService addressService = new Rock.CRM.AddressService(); Rock.CRM.Address addressModel = addressService.Geocode(address, user.PersonId); return(addressModel.DataTransferObject); } else { throw new WebFaultException <string>("Invalid Address", System.Net.HttpStatusCode.BadRequest); } } else { throw new WebFaultException <string>("Invalid API Key", System.Net.HttpStatusCode.Forbidden); } } }
public Rock.CRM.DTO.Address ApiGet(string id, string apiKey) { using (Rock.Data.UnitOfWorkScope uow = new Rock.Data.UnitOfWorkScope()) { Rock.CMS.UserService userService = new Rock.CMS.UserService(); Rock.CMS.User user = userService.Queryable().Where(u => u.ApiKey == apiKey).FirstOrDefault(); if (user != null) { uow.objectContext.Configuration.ProxyCreationEnabled = false; Rock.CRM.AddressService AddressService = new Rock.CRM.AddressService(); Rock.CRM.Address Address = AddressService.Get(int.Parse(id)); if (Address.Authorized("View", user)) { return(Address.DataTransferObject); } else { throw new WebFaultException <string>("Not Authorized to View this Address", System.Net.HttpStatusCode.Forbidden); } } else { throw new WebFaultException <string>("Invalid API Key", System.Net.HttpStatusCode.Forbidden); } } }
public void UpdateAddress(string id, Rock.CRM.DTO.Address Address) { var currentUser = Rock.CMS.UserService.GetCurrentUser(); if (currentUser == null) { throw new WebFaultException <string>("Must be logged in", System.Net.HttpStatusCode.Forbidden); } using (Rock.Data.UnitOfWorkScope uow = new Rock.Data.UnitOfWorkScope()) { uow.objectContext.Configuration.ProxyCreationEnabled = false; Rock.CRM.AddressService AddressService = new Rock.CRM.AddressService(); Rock.CRM.Address existingAddress = AddressService.Get(int.Parse(id)); if (existingAddress.Authorized("Edit", currentUser)) { uow.objectContext.Entry(existingAddress).CurrentValues.SetValues(Address); if (existingAddress.IsValid) { AddressService.Save(existingAddress, currentUser.PersonId); } else { throw new WebFaultException <string>(existingAddress.ValidationResults.AsDelimited(", "), System.Net.HttpStatusCode.BadRequest); } } else { throw new WebFaultException <string>("Not Authorized to Edit this Address", System.Net.HttpStatusCode.Forbidden); } } }
public void ApiDeleteAddress(string id, string apiKey) { using (Rock.Data.UnitOfWorkScope uow = new Rock.Data.UnitOfWorkScope()) { Rock.CMS.UserService userService = new Rock.CMS.UserService(); Rock.CMS.User user = userService.Queryable().Where(u => u.ApiKey == apiKey).FirstOrDefault(); if (user != null) { uow.objectContext.Configuration.ProxyCreationEnabled = false; Rock.CRM.AddressService AddressService = new Rock.CRM.AddressService(); Rock.CRM.Address Address = AddressService.Get(int.Parse(id)); if (Address.Authorized("Edit", user)) { AddressService.Delete(Address, user.PersonId); AddressService.Save(Address, user.PersonId); } else { throw new WebFaultException <string>("Not Authorized to Edit this Address", System.Net.HttpStatusCode.Forbidden); } } else { throw new WebFaultException <string>("Invalid API Key", System.Net.HttpStatusCode.Forbidden); } } }
public void DeleteAddress(string id) { var currentUser = Rock.CMS.UserService.GetCurrentUser(); if (currentUser == null) { throw new WebFaultException <string>("Must be logged in", System.Net.HttpStatusCode.Forbidden); } using (Rock.Data.UnitOfWorkScope uow = new Rock.Data.UnitOfWorkScope()) { uow.objectContext.Configuration.ProxyCreationEnabled = false; Rock.CRM.AddressService AddressService = new Rock.CRM.AddressService(); Rock.CRM.Address Address = AddressService.Get(int.Parse(id)); if (Address.Authorized("Edit", currentUser)) { AddressService.Delete(Address, currentUser.PersonId); AddressService.Save(Address, currentUser.PersonId); } else { throw new WebFaultException <string>("Not Authorized to Edit this Address", System.Net.HttpStatusCode.Forbidden); } } }
public void ApiCreateAddress(string apiKey, Rock.CRM.DTO.Address Address) { using (Rock.Data.UnitOfWorkScope uow = new Rock.Data.UnitOfWorkScope()) { Rock.CMS.UserService userService = new Rock.CMS.UserService(); Rock.CMS.User user = userService.Queryable().Where(u => u.ApiKey == apiKey).FirstOrDefault(); if (user != null) { uow.objectContext.Configuration.ProxyCreationEnabled = false; Rock.CRM.AddressService AddressService = new Rock.CRM.AddressService(); Rock.CRM.Address existingAddress = new Rock.CRM.Address(); AddressService.Add(existingAddress, user.PersonId); uow.objectContext.Entry(existingAddress).CurrentValues.SetValues(Address); if (existingAddress.IsValid) { AddressService.Save(existingAddress, user.PersonId); } else { throw new WebFaultException <string>(existingAddress.ValidationResults.AsDelimited(", "), System.Net.HttpStatusCode.BadRequest); } } else { throw new WebFaultException <string>("Invalid API Key", System.Net.HttpStatusCode.Forbidden); } } }
/// <summary> /// Geocodes the specified address. /// </summary> /// <param name="address">The address.</param> /// <param name="result">The result.</param> /// <returns> /// True/False value of whether the address was standardized was succesfully /// </returns> public override bool Geocode(Rock.CRM.Address address, out string result) { if (address != null) { var registeredUser = new RegisteredUser(); registeredUser.UserID = AttributeValue("UserID"); registeredUser.Password = AttributeValue("Password"); var licenseInfo = new LicenseInfo(); licenseInfo.RegisteredUser = registeredUser; var client = new USAddressVerificationSoapClient(); SIWsOutputOfUSAddress verifyResult; SubscriptionInfo info = client.VerifyAddressUSA( licenseInfo, address.Street1, address.Street2, string.Format("{0} {1} {2}", address.City, address.State, address.Zip), string.Empty, string.Empty, CasingEnum.PROPER, out verifyResult); if (verifyResult != null) { result = verifyResult.ServiceStatus.StatusNbr.ToString(); if (verifyResult.ServiceStatus.StatusNbr == 200) { USAddress usAddress = verifyResult.ServiceResult; if (usAddress != null && usAddress.GeoCode != null) { address.Latitude = usAddress.GeoCode.Latitude; address.Longitude = usAddress.GeoCode.Longitude; return(true); } } } else { result = "Null Result"; } } else { result = "Null Address"; } return(false); }
/// <summary> /// Standardizes the address /// </summary> /// <param name="address">The address.</param> /// <param name="result">The AddressCheck result code</param> /// <returns> /// True/False value of whether the address was standardized succesfully /// </returns> public override bool Standardize(Rock.CRM.Address address, out string result) { if (address != null) { var requestArray = new RequestArray(); requestArray.CustomerID = AttributeValue("CustomerId"); requestArray.OptAddressParsed = "True"; RequestArrayRecord requestAddress = new RequestArrayRecord(); requestAddress.AddressLine1 = address.Street1; requestAddress.AddressLine2 = address.Street2; requestAddress.City = address.City; requestAddress.State = address.State; requestAddress.Zip = address.Zip; requestAddress.RecordID = "1"; requestArray.Record = new RequestArrayRecord[1]; requestArray.Record[0] = requestAddress; ServiceClient serviceClient = new ServiceClient(); var responseArray = serviceClient.doAddressCheck(requestArray); if (responseArray.TotalRecords == "1" && responseArray.Record[0].RecordID == "1") { result = responseArray.Record[0].Results; if (responseArray.Record[0].Results.Contains("AS01")) { ResponseArrayRecordAddress responseAddress = responseArray.Record[0].Address; address.Street1 = responseAddress.Address1; address.Street2 = responseAddress.Address2; address.City = responseAddress.City.Name; address.State = responseAddress.State.Abbreviation; address.Zip = responseAddress.Zip + '-' + responseAddress.Plus4; if (address.Street2.Trim() == string.Empty && responseAddress.Suite.Trim() != string.Empty) { address.Street2 = responseAddress.Suite; } return(true); } } else { result = "No Records Returned"; } } else { result = "Null Address"; } return(false); }
public Rock.CRM.DTO.Address Standardize(Rock.CRM.DTO.Address address) { var currentUser = Rock.CMS.UserService.GetCurrentUser(); if (currentUser == null) { throw new WebFaultException <string>("Must be logged in", System.Net.HttpStatusCode.Forbidden); } using (new Rock.Data.UnitOfWorkScope()) { if (address != null) { Rock.CRM.AddressService addressService = new Rock.CRM.AddressService(); Rock.CRM.Address addressModel = addressService.Standardize(address, currentUser.PersonId); return(addressModel.DataTransferObject); } else { throw new WebFaultException <string>("Invalid Address", System.Net.HttpStatusCode.BadRequest); } } }
public void ApiCreateAddress( string apiKey, Rock.CRM.DTO.Address Address ) { using ( Rock.Data.UnitOfWorkScope uow = new Rock.Data.UnitOfWorkScope() ) { Rock.CMS.UserService userService = new Rock.CMS.UserService(); Rock.CMS.User user = userService.Queryable().Where( u => u.ApiKey == apiKey ).FirstOrDefault(); if (user != null) { uow.objectContext.Configuration.ProxyCreationEnabled = false; Rock.CRM.AddressService AddressService = new Rock.CRM.AddressService(); Rock.CRM.Address existingAddress = new Rock.CRM.Address(); AddressService.Add( existingAddress, user.PersonId ); uow.objectContext.Entry(existingAddress).CurrentValues.SetValues(Address); if (existingAddress.IsValid) AddressService.Save( existingAddress, user.PersonId ); else throw new WebFaultException<string>( existingAddress.ValidationResults.AsDelimited(", "), System.Net.HttpStatusCode.BadRequest ); } else throw new WebFaultException<string>( "Invalid API Key", System.Net.HttpStatusCode.Forbidden ); } }
public Rock.CRM.DTO.Address Get(string id) { var currentUser = Rock.CMS.UserService.GetCurrentUser(); if (currentUser == null) { throw new WebFaultException <string>("Must be logged in", System.Net.HttpStatusCode.Forbidden); } using (Rock.Data.UnitOfWorkScope uow = new Rock.Data.UnitOfWorkScope()) { uow.objectContext.Configuration.ProxyCreationEnabled = false; Rock.CRM.AddressService AddressService = new Rock.CRM.AddressService(); Rock.CRM.Address Address = AddressService.Get(int.Parse(id)); if (Address.Authorized("View", currentUser)) { return(Address.DataTransferObject); } else { throw new WebFaultException <string>("Not Authorized to View this Address", System.Net.HttpStatusCode.Forbidden); } } }
public void CreateAddress( Rock.CRM.DTO.Address Address ) { var currentUser = Rock.CMS.UserService.GetCurrentUser(); if ( currentUser == null ) throw new WebFaultException<string>("Must be logged in", System.Net.HttpStatusCode.Forbidden ); using ( Rock.Data.UnitOfWorkScope uow = new Rock.Data.UnitOfWorkScope() ) { uow.objectContext.Configuration.ProxyCreationEnabled = false; Rock.CRM.AddressService AddressService = new Rock.CRM.AddressService(); Rock.CRM.Address existingAddress = new Rock.CRM.Address(); AddressService.Add( existingAddress, currentUser.PersonId ); uow.objectContext.Entry(existingAddress).CurrentValues.SetValues(Address); if (existingAddress.IsValid) AddressService.Save( existingAddress, currentUser.PersonId ); else throw new WebFaultException<string>( existingAddress.ValidationResults.AsDelimited(", "), System.Net.HttpStatusCode.BadRequest ); } }
/// <summary> /// Abstract method for standardizing the specified address. Derived classes should implement /// this method to standardize the address. /// </summary> /// <param name="address">The address.</param> /// <param name="result">The result code unique to the service.</param> /// <returns> /// True/False value of whether the address was standardized succesfully /// </returns> public abstract bool Standardize(Rock.CRM.Address address, out string result);
/// <summary> /// Abstract method for geocoding the specified address. Derived classes should implement /// this method to geocode the address. /// </summary> /// <param name="address">The address.</param> /// <param name="result">The result code unique to the service.</param> /// <returns> /// True/False value of whether the address was standardized succesfully /// </returns> public abstract bool Geocode(Rock.CRM.Address address, out string result);
/// <summary> /// Geocodes the specified address. /// </summary> /// <param name="address">The address.</param> /// <param name="result">The result.</param> /// <returns> /// True/False value of whether the address was standardized was succesfully /// </returns> public override bool Geocode(Rock.CRM.Address address, out string result) { if (address != null) { var aptc = new Rock.TeleAtlas.Authentication.AuthenticationPortTypeClient(); int encryptedId; int rc = aptc.requestChallenge(AttributeValue("UserID"), 0, out encryptedId); if (rc == 0) { int key = elfHash(AttributeValue("Password")); int unencryptedChallenge = encryptedId ^ key; int permutedChallenge = permute(unencryptedChallenge); int response = permutedChallenge ^ key; int cred; rc = aptc.answerChallenge(response, encryptedId, out cred); if (rc == 0) { var addressParts = new Rock.TeleAtlas.Geocoding.NameValue[5]; addressParts[0] = NameValue("Addr", string.Format("{0} {1}", address.Street1, address.Street2)); addressParts[1] = NameValue("City", address.City); addressParts[2] = NameValue("State", address.State); addressParts[3] = NameValue("ZIP", address.Zip); addressParts[4] = NameValue("Plus4", string.Empty); var gptc = new Rock.TeleAtlas.Geocoding.GeocodingPortTypeClient(); Rock.TeleAtlas.Geocoding.Geocode returnedGeocode; rc = gptc.findAddress(AttributeValue("EZLocateService"), addressParts, cred, out returnedGeocode); if (rc == 0) { if (returnedGeocode.resultCode == 0) { Rock.TeleAtlas.Geocoding.NameValue matchType = null; Rock.TeleAtlas.Geocoding.NameValue latitude = null; Rock.TeleAtlas.Geocoding.NameValue longitude = null; foreach (var attribute in returnedGeocode.mAttributes) { switch (attribute.name) { case "MAT_TYPE": matchType = attribute; break; case "MAT_LAT": latitude = attribute; break; case "MAT_LONG": longitude = attribute; break; } } if (matchType != null) { result = matchType.value; if (matchType.value == "1") { address.Latitude = double.Parse(latitude.value); address.Longitude = double.Parse(longitude.value); return(true); } } else { result = "No Match"; } } else { result = string.Format("No Match (requestChallenge result: {0})", rc); } } else { result = string.Format("No Match (geocode result: {0})", rc); } } else { result = string.Format("Could not authenticate (answerChallenge result: {0})", rc); } } else { result = string.Format("Could not authenticate (findAddress result: {0})", rc); } } else { result = "Null Address"; } return(false); }