public pgEditStatics()
 {
     InitializeComponent();
     btnBack = (Button)myStackLayout.Children[2];
     pckStatics.Items.Clear();
     foreach (string name in InfoStore.getStaticNames())
     {
         pckStatics.Items.Add(name);
     }
     pckStatics.Items.Add("Add New Statics");
     if (Device.RuntimePlatform == Device.Android)
     {
         backButton.IsVisible = false;
     }
 }
Exemple #2
0
        private void performSave()
        {
            string JSONToPatch = "{";

            //string JSONToPatch = JsonConvert.SerializeObject(new Static(txtName.Text.Trim(), txtDesc.Text.Trim(), txtImage.Text.Trim()));

            foreach (View v in stkLayout.Children)
            {
                if (v.GetType() == typeof(Entry))
                {
                    Entry txtBox = v as Entry;
                    JSONToPatch += "\"" + txtBox.AutomationId + "\":\"" + txtBox.Text.Trim() + "\",";
                }
                else if (v.GetType() == typeof(Editor))
                {
                    Editor txtBox = v as Editor;
                    JSONToPatch += "\"" + txtBox.AutomationId + "\":\"" + txtBox.Text.Trim() + "\",";
                }
            }

            JSONToPatch += "\" Last Updated By \":\"" + current.localId + "\"}";

            if (index > InfoStore.getStaticNames().Count)
            {
                try
                {
                    User   currentUser = InfoStore.CurrentUser;
                    string target      = "https://airshowapp-d193b.firebaseio.com/Airshows/" + InfoStore.getAirshowIndex(InfoStore.Selected) + "/Statics/" + index.ToString() + ".json?auth=" + currentUser.token;

                    ServicePointManager.ServerCertificateValidationCallback += (send, certificate, chain, sslPolicyErrors) => { return(true); };

                    WebClient client = new WebClient();
                    client.Headers[HttpRequestHeader.ContentType] = "application/json";
                    string rawResponse = client.UploadString(new Uri(target), "PUT", JSONToPatch);

                    Console.Write("Response is: " + rawResponse);

                    InfoStore.getDatabase();

                    LoadPage(new pgEditStatics());
                }
                catch (Exception E)
                {
                    Console.WriteLine(E.ToString());
                }
            }
            else
            {
                try
                {
                    JSONToPatch = String.Concat(" ", JSONToPatch);
                    User   currentUser = InfoStore.CurrentUser;
                    string target      = "https://airshowapp-d193b.firebaseio.com/Airshows/" + InfoStore.getAirshowIndex(InfoStore.Selected) + "/Statics/" + index.ToString() + ".json?auth=" + currentUser.token;

                    ServicePointManager.ServerCertificateValidationCallback += (send, certificate, chain, sslPolicyErrors) => { return(true); };

                    WebClient client = new WebClient();
                    client.Headers[HttpRequestHeader.ContentType] = "application/json";
                    string  rawResponse = client.UploadString(new Uri(target), "PUT", JSONToPatch);
                    JObject response    = JObject.Parse(rawResponse);

                    Console.Write("Response is: " + rawResponse);

                    InfoStore.getDatabase();
                    LoadPage(new pgEditStatics());
                }
                catch (Exception E)
                {
                    App.Current.MainPage.DisplayAlert("Save Error", "There was an error saving this entry.  Make sure that all fields are valid and try again", "OK");
                    Console.WriteLine(E.ToString());
                }
            }
        }