private async void OpenPage(string value) { if (string.IsNullOrWhiteSpace(NewEmail) || string.IsNullOrWhiteSpace(OldEmail) || string.IsNullOrWhiteSpace(ConfirmEmail)) { await App.Current.MainPage.DisplayAlert(AppResource.er, AppResource.body, AppResource.ok); } else if (!EmailRegex.IsMatch(OldEmail)) { await App.Current.MainPage.DisplayAlert(AppResource.er, AppResource.emv, AppResource.ok); } else if (!EmailRegex.IsMatch(NewEmail)) { await App.Current.MainPage.DisplayAlert(AppResource.er, AppResource.emv, AppResource.ok); } else if (ConfirmEmail != NewEmail) { await App.Current.MainPage.DisplayAlert(AppResource.er, AppResource.emt, AppResource.ok); } else { if (Settings.AccessToken == "") { await App.Current.MainPage.DisplayAlert(AppResource.er, AppResource.nonuser, AppResource.ok); await Application.Current.MainPage.Navigation.PushModalAsync(new LoginPage()); } else { var nemail = new NEmail { OldEmail = OldEmail, NewEmail = NewEmail, }; DependencyService.Get <IProgressInterface>().Show(); var IsChange = await _apiService.ChangeEmailAsync(nemail, Settings.AccessToken); DependencyService.Get <IProgressInterface>().Hide(); if (IsChange) { Settings.Email = NewEmail; await Application.Current.MainPage.Navigation.PushModalAsync(new MainMenu()); } else { await App.Current.MainPage.DisplayAlert(AppResource.er, AppResource.problem, AppResource.ok); await Application.Current.MainPage.Navigation.PushModalAsync(new ChangeEmail()); } } } }
public async Task <bool> ChangeEmailAsync(NEmail nemail, string accessToken) { var client = new HttpClient(); client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken); var json = JsonConvert.SerializeObject(nemail); HttpContent content = new StringContent(json); content.Headers.ContentType = new MediaTypeHeaderValue("application/json"); var response = await client.PostAsync(Constants.BaseApiAddress + "api/Account/ChangeEmail", content); if (response.IsSuccessStatusCode) { return(true); } return(false); }