private async void GetPostalCode(object sender, TappedRoutedEventArgs e) { var geo = new Geolocator(); Geoposition pos = await geo.GetGeopositionAsync().AsTask(); PostalCodeImg.IsTapEnabled = false; var postCode = string.Empty; try { PostCodeRing.IsActive = true; postCode = await Task <string> .Run(() => GeocodeServiceHelper.GetPostalCode(pos)); if (postCode.Length <= 0) { PCNotFoundTxt.Visibility = Visibility.Visible; } else { PostalCodeText.Text = postCode; } PostCodeRing.IsActive = false; } catch (Exception) { PostCodeRing.IsActive = false; } PostalCodeImg.IsTapEnabled = true; }
private async void GetLocation(object sender, TappedRoutedEventArgs e) { PostalCodeImg.IsTapEnabled = false; CityImg.IsTapEnabled = false; CountryImg.IsTapEnabled = false; var activeRing = PostCodeRing; try { Image clicked = (Image)sender; switch (clicked.Name) { case "PostalCodeImg": PostCodeRing.IsActive = true; break; case "CityImg": CityRing.IsActive = true; activeRing = CityRing; break; case "CountryImg": CountryRing.IsActive = true; activeRing = CountryRing; break; } var geo = new Geolocator(); Geoposition pos = await geo.GetGeopositionAsync().AsTask(); var location = await Task <GeocodeResponse> .Run(() => GeocodeServiceHelper.GetLocation(pos)); if (location.Results != null) { PostalCodeTxt.Text = location.Results[0].Address.PostalCode; CityTxt.Text = location.Results[0].Address.Locality; CountryCombo.SelectedValue = location.Results[0].Address.CountryRegion; StateCombo.SelectedValue = location.Results[0].Address.AdminDistrict; } activeRing.IsActive = false; } catch (Exception) { activeRing.IsActive = false; PostalCodeImg.IsTapEnabled = true; CityImg.IsTapEnabled = true; CountryImg.IsTapEnabled = true; } PostalCodeImg.IsTapEnabled = true; CityImg.IsTapEnabled = true; CountryImg.IsTapEnabled = true; }
private async void Search() { decimal latitude = 0; decimal longitude = 0; var emptyString = "\"\""; var age = AgeText.Text.Length > 0 ? Int32.Parse(AgeText.Text) : -1; var gender = GenderCombo.SelectedValue != null?GenderCombo.SelectedValue.ToString() : emptyString; var conditions = ConditionText.Text.Length > 0 ? ConditionText.Text : emptyString; var postalCode = PostalCodeText.Text.Length > 0 ? PostalCodeText.Text : emptyString; var distance = DistanceCombo.SelectedValue != null ? (DistanceCombo.SelectedValue.ToString() == "Any" ? 1000000 : Int32.Parse(DistanceCombo.SelectedValue.ToString())) : 1000000; var postCode = PostalCodeText.Text; if (postCode.Length > 0 && postCode != SuspensionManager.SessionState["PostCode"].ToString()) { try { var response = await Task <string> .Run(() => GeocodeServiceHelper.GetGeocodeByAddress(postCode)); if (response.Results != null) { latitude = Convert.ToDecimal(response.Results[0].Locations[0].Latitude); longitude = Convert.ToDecimal(response.Results[0].Locations[0].Longitude); } } catch (Exception) { // Swallow exception } } else { latitude = Convert.ToDecimal(SuspensionManager.SessionState["Latitude"].ToString()); longitude = Convert.ToDecimal(SuspensionManager.SessionState["Longitude"].ToString()); } var paramSet = new Dictionary <string, string>(); paramSet.Add("age", age.ToString()); paramSet.Add("gender", gender); paramSet.Add("conditions", conditions); paramSet.Add("postalCode", postalCode); paramSet.Add("distance", distance.ToString()); SetSessionVariable("SearchParams", paramSet); ProgressStatus.Visibility = Visibility.Visible; _viewModel.GetResearchStudies(age, gender, conditions, postalCode, emptyString, distance, latitude, longitude, 0, 50, "1900-01-01"); }
private async void SetLocation(User user) { decimal latitude = 0; decimal longitude = 0; var postCode = string.Empty; SuspensionManager.SessionState.Add("PostCode", postCode); SuspensionManager.SessionState.Add("Latitude", latitude); SuspensionManager.SessionState.Add("Longitude", longitude); if (user != null && user.zip_code != null) { postCode = user.zip_code; } else { var geo = new Geolocator(); Geoposition pos = await geo.GetGeopositionAsync().AsTask(); postCode = await Task <string> .Run(() => GeocodeServiceHelper.GetPostalCode(pos)); } if (postCode.Length > 0) { SuspensionManager.SessionState["PostCode"] = postCode; var response = await Task <string> .Run(() => GeocodeServiceHelper.GetGeocodeByAddress(postCode)); if (response.Results != null) { latitude = Convert.ToDecimal(response.Results[0].Locations[0].Latitude); longitude = Convert.ToDecimal(response.Results[0].Locations[0].Longitude); SuspensionManager.SessionState["Latitude"] = latitude; SuspensionManager.SessionState["Longitude"] = longitude; } } }
private async void Save() { ViewModel.SavingData = true; if ((EmailTxt.Text == null || EmailTxt.Text.Length <= 0) && IsValid(EmailTxt.Text)) { var md = new MessageDialog("A valid email address is required."); await md.ShowAsync(); return; } var year = YearList.SelectedValue != null?YearList.SelectedValue.ToString() : string.Empty; DateTime birthDate; if (year.Length > 0 || DayList.SelectedValue != null || MonthList.SelectedValue != null) { var day = DayList.SelectedValue != null?DayList.SelectedValue.ToString() : "1"; var month = MonthList.SelectedValue != null?MonthList.SelectedValue.ToString() : "1"; var dateString = month + "/" + day + "/" + year; if (DateTime.TryParse(dateString, out birthDate) == false) { var md = new MessageDialog("The birth date is invalid"); await md.ShowAsync(); return; } ViewModel.CurrentUser.DOB = birthDate; } var address = AddressTxt.Text + " " + PostalCodeTxt.Text; if (address.Length > 0) { try { var location = await Task <GeocodeResponse> .Run(() => GeocodeServiceHelper.GetGeocodeByAddress(address)); if (location.Results != null) { var lat = location.Results[0].Locations[0].Latitude; var lon = location.Results[0].Locations[0].Longitude; } } catch (Exception) { } } ViewModel.CurrentUser.first_name = FirstNameTxt.Text; ViewModel.CurrentUser.last_name = LastNameTxt.Text; ViewModel.CurrentUser.address_1 = AddressTxt.Text; ViewModel.CurrentUser.city = CityTxt.Text; ViewModel.CurrentUser.zip_code = PostalCodeTxt.Text; ViewModel.CurrentUser.country = CountryCombo.SelectedValue != null?CountryCombo.SelectedValue.ToString() : string.Empty; ViewModel.CurrentUser.email_address = EmailTxt.Text; ViewModel.CurrentUser.state = StateCombo.SelectedValue != null?StateCombo.SelectedValue.ToString() : string.Empty; ViewModel.CurrentUser.mobile_phone = MobileNumber.Text; ViewModel.CurrentUser.Gender = GenderCombo.SelectedValue != null?GenderCombo.SelectedValue.ToString() == "Male" ? "M" : "F" : string.Empty; await ViewModel.SaveUser(ViewModel.CurrentUser, ConditionTxt.Text, MedicationTxt.Text); SuspensionManager.SessionState["CurrentUser"] = ViewModel.CurrentUser; }