async Task RegistrationAsync()
        {
            ShowProgressDialogue("Registering...please wait!");
            try
            {
                var HttpClient = SessionManager.GetHttpClient();
                var json       = JsonConvert.SerializeObject(CurMember);
                var content    = new StringContent(json, Encoding.UTF8, "application/json");
                var url        = SessionManager.GetAPIURL("farmerRegistrations");
                var req        = new HttpRequestMessage(HttpMethod.Post, url)
                {
                    Content = content,
                };
                var response = await HttpClient.PostAsync(url, content);

                var responseMsg = await response.Content.ReadAsStringAsync();

                if (!string.IsNullOrWhiteSpace(responseMsg))
                {
                    var json1 = JsonConvert.DeserializeObject <dynamic>(responseMsg);
                    if (response.IsSuccessStatusCode)
                    {
                        CurMember.IsSynced = true;
                        Farmer.DB.Update(CurMember);
                        Android.App.AlertDialog.Builder dialog = new Android.App.AlertDialog.Builder(this);
                        Android.App.AlertDialog         alert  = dialog.Create();
                        alert.SetTitle("Registration");
                        alert.SetCanceledOnTouchOutside(false);
                        alert.SetMessage("Registration was successful. You can now login. Your username is your mobile number. Use any PIN or password of choice.");
                        alert.SetIcon(Resource.Drawable.ic_account_key);
                        alert.SetButton("OK", (c, ev) =>
                        {
                            alert.Dismiss();
                            var intent = new Intent(this, typeof(LoginActivity));
                            intent.PutExtra("Username", CurMember.Mobile);
                            StartActivity(intent);
                            Finish();
                            OverridePendingTransition(Resource.Animation.side_in_right, Resource.Animation.side_out_left);
                        });
                        alert.Show();
                    }
                    else
                    {
                        CloseProgressDialogue();
                        MessageBox.Show(this, "Regidtration Error", (string)json1.error_description);
                    }
                }
            }
            catch (Exception e)
            {
                CloseProgressDialogue();
                this.Show("Error", e.Message);
            }
        }
Esempio n. 2
0
        async Task RegistrationAsync()
        {
            ProgressBar.Visibility = ViewStates.Visible;
            BtnLogin.Enabled       = false;
            try
            {
                var HttpClient = SessionManager.GetHttpClient();
                var json       = JsonConvert.SerializeObject(CurMember);
                var content    = new StringContent(json, Encoding.UTF8, "application/json");
                var url        = SessionManager.GetAPIURL("extensionOfficerRegistrations");
                var req        = new HttpRequestMessage(HttpMethod.Post, url)
                {
                    Content = content,
                };
                var response = await HttpClient.PostAsync(url, content);

                var responseMsg = await response.Content.ReadAsStringAsync();

                if (!string.IsNullOrWhiteSpace(responseMsg))
                {
                    var json1 = JsonConvert.DeserializeObject <ExtensionOfficer>(responseMsg);
                    if (response.IsSuccessStatusCode)
                    {
                        if (json1.ErrorCode.HasValue)
                        {
                            if (json1.ErrorCode == -1)
                            {
                                MessageBox.Show(this, "Record not found", json1.Firstname);
                            }
                            if (json1.ErrorCode == 1)
                            {
                                Android.App.AlertDialog.Builder dialog = new Android.App.AlertDialog.Builder(this);
                                Android.App.AlertDialog         alert  = dialog.Create();
                                alert.SetTitle("Record found");
                                alert.SetCanceledOnTouchOutside(false);
                                alert.SetMessage(json1.Firstname);
                                alert.SetIcon(Resource.Drawable.ic_account_key);
                                alert.SetButton("OK", (c, ev) =>
                                {
                                    alert.Dismiss();
                                    var intent = new Intent(this, typeof(LoginActivity));
                                    intent.PutExtra("Username", CurMember.ECNumber);
                                    StartActivity(intent);
                                    Finish();
                                    OverridePendingTransition(Resource.Animation.side_in_right, Resource.Animation.side_out_left);
                                });
                                alert.Show();
                            }
                        }

                        else
                        {
                            CurMember.IsSynced = true;
                            ExtensionOfficer.DB.Update(CurMember);
                            Android.App.AlertDialog.Builder dialog = new Android.App.AlertDialog.Builder(this);
                            Android.App.AlertDialog         alert  = dialog.Create();
                            alert.SetTitle("Registration");
                            alert.SetCanceledOnTouchOutside(false);
                            alert.SetMessage("Registration was successful. You can now login. Your username is your EC number. Use any PIN or password of choice.");
                            alert.SetIcon(Resource.Drawable.ic_account_key);
                            alert.SetButton("OK", (c, ev) =>
                            {
                                alert.Dismiss();
                                var intent = new Intent(this, typeof(LoginActivity));
                                intent.PutExtra("Username", CurMember.ECNumber);
                                StartActivity(intent);
                                Finish();
                                OverridePendingTransition(Resource.Animation.side_in_right, Resource.Animation.side_out_left);
                            });
                            alert.Show();
                        }
                    }
                    else
                    {
                        MessageBox.Show(this, "Regidtration Error", "Unknown error");
                    }
                }
            }
            catch (Exception e)
            {
                this.Show("Error", e.Message);
                BtnLogin.Enabled       = true;
                ProgressBar.Visibility = ViewStates.Gone;
            }
        }