Exemple #1
0
 static async void SendMessageToMainPage(string body)
 {
     Device.BeginInvokeOnMainThread(() => {
         MsgPage.initMessages();
     });
 }
Exemple #2
0
        async void changeName(object sender, EventArgs e)
        {
            var    url         = "https://jax-apps.com/api.php";
            string f           = firstEntry.Text.ToString();
            string l           = secondEntry.Text.ToString();
            var    formContent = new FormUrlEncodedContent(new[]
            {
                new KeyValuePair <string, string>("nameChange", LoginViewModel.user.employee_id.ToString()),
                new KeyValuePair <string, string>("first", f),
                new KeyValuePair <string, string>("second", l)
            });


            //perform POST operation
            var myHttpClient = new HttpClient();

            HttpResponseMessage response = new HttpResponseMessage();

            try
            {
                response = await myHttpClient.PostAsync(url, formContent);



                if (response.Content == null)
                {
                    await App.Current.MainPage.DisplayAlert("Error", "Unable to reach server", "OK");
                }
                var result = await response.Content.ReadAsStringAsync();

                if (result.Contains("Success"))
                {
                    await App.Current.MainPage.DisplayAlert("Success", "Name Changed.", "OK");

                    LoginViewModel.user.firstname = f;
                    LoginViewModel.user.lastname  = l;
                    MsgPage.updateName("");
                    flName.Text           = f + " " + l;
                    popupCreate.IsVisible = false;
                }
                else
                {
                    await App.Current.MainPage.DisplayAlert("Error", "Please Submit a Ticket", "OK");
                }
            }


            catch (Exception ex)
            {
                retryCount++;
                if (retryCount < 11)
                {
                    changeName(sender, e);
                    return;
                }
                else
                {
                    await App.Current.MainPage.DisplayAlert("Error", ex.ToString(), "OK");
                }
            }
            retryCount = 0;
        }