public IActionResult GetTempPolicy([FromBody] dynamic data) { TempPolicy tempPolicy = Utils.ConvertTo <TempPolicy>(data); string currentCity = _cityRepository.Retrieve(Int32.Parse(tempPolicy.CityId)).Name; string currentState = _stateRepository.Retrieve(tempPolicy.StateId).Name; string fullAddress = tempPolicy.Address1 + " " + tempPolicy.Address2 + " " + currentCity + " " + currentState + " " + tempPolicy.ZipCode; var result = new TempPolicy { InsuredFirstName = tempPolicy.InsuredFirstName, InsuredMiddleName = tempPolicy.InsuredMiddleName, InsuredLastName = tempPolicy.InsuredLastName, Address = fullAddress, Address1 = tempPolicy.Address1, Address2 = tempPolicy.Address2, InsuredCity = currentCity, InsuredState = currentState, InsuredZipCode = tempPolicy.ZipCode, PolicyNumber = tempPolicy.PolicyNumber, WildfireAssessmentRequired = false, Longitude = "", Latitude = "", CityId = tempPolicy.CityId, StateId = tempPolicy.StateId, ZipCode = tempPolicy.ZipCode, InsuredEmail = AppSettings.Configuration["InsuredEmail"] }; result = _mapService.GetAddressGeocode(result); return(Ok(result)); }
public TempPolicy GetAddressGeocode(TempPolicy policy) { string requestUri = $"https://maps.googleapis.com/maps/api/geocode/json?address={Uri.EscapeDataString(policy.Address)}&key=AIzaSyD93rX1ZlgbN3tEieWTMtqH9BwoXEHLDI0"; var result = new System.Net.WebClient().DownloadString(requestUri); GoogleMapApiResponse googleResponse = JsonConvert.DeserializeObject <GoogleMapApiResponse>(result); if (googleResponse.results.Length != 0) { policy.Latitude = googleResponse.results.First().geometry.location.lat.ToString(); policy.Longitude = googleResponse.results.First().geometry.location.lng.ToString(); } return(policy); }