protected void SavePlot(ProgressDialog dialog, Activity curActivity, PlotDetailResponse obj)
        {
            try
            {
                string mStringLoginInfo    = string.Empty;
                string mStringSessionToken = string.Empty;
                try
                {
                    objdb = new DBaseOperations();
                    var lstu = objdb.selectTable();
                    if (lstu != null && lstu.Count > default(int))
                    {
                        var uobj = lstu.FirstOrDefault();
                        if (uobj.Password == " ")
                        {
                            throw new Exception("Please login again");
                        }
                        mStringLoginInfo    = uobj.EmailId;
                        mStringSessionToken = uobj.AuthToken;
                    }
                }
                catch { }

                var client  = new RestClient(Common.UrlBase);
                var request = new RestRequest("Plot/CreateUpdatePlot", Method.POST);
                request.AddHeader("Content-Type", "application/json");
                request.AddHeader("TokenKey", mStringSessionToken);
                request.AddJsonBody(new { PlotName = obj.PlotName, PlotSize = obj.PlotSize, Organic = obj.Organic, SoilPhId = obj.SoilPhId, SoilId = obj.SoilId, Notes = obj.Notes, FarmId = obj.FarmId, PlotId = obj.PlotId });
                IRestResponse response    = client.Execute(request);
                var           content     = response.Content;
                var           responseObj = Newtonsoft.Json.JsonConvert.DeserializeObject <PlotDetailResponse>(content);
                if (response.StatusCode == System.Net.HttpStatusCode.OK)
                {
                    if (responseObj.Status == ResponseStatus.Successful)
                    {
                        curActivity.RunOnUiThread(() =>
                        {
                            Android.App.AlertDialog.Builder alertDiag = new Android.App.AlertDialog.Builder(curActivity);
                            alertDiag.SetTitle(Resource.String.DialogHeaderGeneric);
                            alertDiag.SetMessage(string.Format("'{0}' plot has been {1} successfully", obj.PlotName, (string.IsNullOrEmpty(obj.PlotId) ? "saved" : "updated")));
                            alertDiag.SetIcon(Resource.Drawable.success);
                            alertDiag.SetPositiveButton(Resource.String.DialogButtonOk, (senderAlert, args) =>
                            {
                                MyFarmDashboardFragment objFragment           = new MyFarmDashboardFragment();
                                Android.Support.V4.App.FragmentTransaction tx = FragmentManager.BeginTransaction();
                                tx.Replace(Resource.Id.m_main, objFragment, Constants.myfarmdash);
                                tx.Commit();
                            });
                            Dialog diag = alertDiag.Create();
                            diag.Show();
                            diag.SetCanceledOnTouchOutside(false);
                        });
                    }
                    else
                    {
                        if (!string.IsNullOrEmpty(responseObj.Error))
                        {
                            throw new Exception(responseObj.Error);
                        }
                        else
                        {
                            throw new Exception("Unable to save data now. Please try again later");
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                curActivity.RunOnUiThread(() =>
                {
                    Android.App.AlertDialog.Builder alertDiag = new Android.App.AlertDialog.Builder(curActivity);
                    alertDiag.SetTitle(Resource.String.DialogHeaderError);
                    alertDiag.SetMessage(ex.Message);
                    alertDiag.SetIcon(Resource.Drawable.alert);
                    alertDiag.SetPositiveButton(Resource.String.DialogButtonOk, (senderAlert, args) =>
                    {
                    });
                    Dialog diag = alertDiag.Create();
                    diag.Show();
                    diag.SetCanceledOnTouchOutside(false);
                });
            }
            finally
            {
                if (dialog != null && dialog.IsShowing)
                {
                    dialog.Hide();
                    dialog.Dismiss();
                }
            }
        }
        protected void AddPlot_Clicked(object sender, EventArgs e, Activity currentActivity)
        {
            try
            {
                btn_add_new_plot.Click -= (sndr, argus) => AddPlot_Clicked(sndr, argus, currentActivity);

                if (string.IsNullOrEmpty(input_plot_name.Text.Trim()) || string.IsNullOrEmpty(input_plot_size.Text.Trim()))
                {
                    throw new Exception("Please do not leave any mandatory field blank");
                }
                if (string.IsNullOrWhiteSpace(spinnersoilphtxt) || string.IsNullOrWhiteSpace(spinnersoiltypetxt))
                {
                    throw new Exception("Please select Soil Ph and Soil Type");
                }

                string plotid = string.Empty;
                try
                {
                    plotid = Arguments.GetString("siteparam0");
                }
                catch { }

                currentActivity.RunOnUiThread(() =>
                {
                    Android.App.AlertDialog.Builder alertDiag = new Android.App.AlertDialog.Builder(currentActivity);
                    alertDiag.SetTitle(Resource.String.DialogHeaderGeneric);
                    alertDiag.SetMessage(string.Format("Are you sure you want to {0} '{1}' plot?", (!string.IsNullOrEmpty(plotid) ? "update" : "save"), input_plot_name.Text.Trim()));
                    alertDiag.SetIcon(Resource.Drawable.alert);
                    alertDiag.SetPositiveButton(Resource.String.DialogButtonYes, (senderAlert, args) =>
                    {
                        PlotDetailResponse obj = new PlotDetailResponse();
                        obj.PlotId             = plotid;
                        obj.FarmId             = Arguments.GetString("siteparam");
                        obj.Notes      = input_plot_notes.Text;
                        obj.Organic    = isorganic;
                        obj.PlotName   = input_plot_name.Text.Trim();
                        decimal plSize = default(decimal);
                        decimal.TryParse(input_plot_size.Text.Trim(), out plSize);
                        obj.PlotSize = plSize;
                        if (soilMstrBasu.soildetail.Where(s => s.SoilName == spinnersoiltypetxt).FirstOrDefault() != null)
                        {
                            obj.SoilId = soilMstrBasu.soildetail.Where(s => s.SoilName == spinnersoiltypetxt).ToList().FirstOrDefault().SoilId;
                        }
                        else
                        {
                            obj.SoilId = string.Empty;
                        }
                        if (soilMstrBasu.soilphdetail.Where(s => s.SoilPhvalue.ToString() == spinnersoilphtxt).FirstOrDefault() != null)
                        {
                            obj.SoilPhId = soilMstrBasu.soilphdetail.Where(s => s.SoilPhvalue == Convert.ToInt32(spinnersoilphtxt)).ToList().FirstOrDefault().SoilPhId;
                        }
                        else
                        {
                            obj.SoilPhId = string.Empty;
                        }
                        ProgressDialog progressDialog = ProgressDialog.Show(this.Activity, "Please wait...", "Submitting your plot data...", true);
                        new Thread(new ThreadStart(delegate
                        {
                            this.Activity.RunOnUiThread(() => this.SavePlot(progressDialog, this.Activity, obj));
                        })).Start();
                    });
                    alertDiag.SetNegativeButton(Resource.String.DialogButtonNo, (senderAlert, args) =>
                    {
                    });
                    Dialog diag = alertDiag.Create();
                    diag.Show();
                    diag.SetCanceledOnTouchOutside(false);
                });
            }
            catch (Exception ex)
            {
                currentActivity.RunOnUiThread(() =>
                {
                    Android.App.AlertDialog.Builder alertDiag = new Android.App.AlertDialog.Builder(currentActivity);
                    alertDiag.SetTitle(Resource.String.DialogHeaderError);
                    alertDiag.SetMessage(ex.Message);
                    alertDiag.SetIcon(Resource.Drawable.alert);
                    alertDiag.SetPositiveButton(Resource.String.DialogButtonOk, (senderAlert, args) =>
                    {
                        //btn_add_new_plot.Click += (sndr, argus) => AddPlot_Clicked(sndr, argus, currentActivity);
                    });
                    Dialog diag = alertDiag.Create();
                    diag.Show();
                    diag.SetCanceledOnTouchOutside(false);
                });
            }
        }