public pgEditDirections() { InitializeComponent(); btnBack = (Button)myStackLayout.Children[2]; pckDirections.Items.Clear(); foreach (string name in InfoStore.getDirectionNames()) { pckDirections.Items.Add(name); } pckDirections.Items.Add("Add new directions"); if (Device.RuntimePlatform == Device.Android) { backButton.IsVisible = false; } }
private void btnDelete_Pressed(object sender, EventArgs e) { InfoStore.getDatabase(); if (Database.Airshows[InfoStore.getAirshowIndex(InfoStore.Selected + 1)].Directions.Count > 1) { performDelete(); } else if (!InfoStore.getDirectionNames().Contains(txtName.Text.Trim())) { LoadPage(new pgEditDirections()); App.Current.MainPage.DisplayAlert("Delete Directions Error", "Error deleting direction set. Please make sure the \"Name\" entry has not been changed", "OK"); } else { LoadPage(new pgEditDirections()); App.Current.MainPage.DisplayAlert("Delete Directions Error", "There must be at least one direction set. Please add another before attempting to delete one", "OK"); } }
private void performSave() { string JSONToPatch = ""; JSONToPatch += "\"" + txtName.AutomationId + "\":\"" + txtName.Text.Trim() + "\","; JSONToPatch += "\"" + pckFull.AutomationId + "\":" + pckFull.SelectedItem.ToString().ToLower() + ","; JSONToPatch += "\"" + txtXCoord.AutomationId + "\":" + Convert.ToDouble(txtXCoord.Text.Trim()) + ","; JSONToPatch += "\"" + txtYCoord.AutomationId + "\":" + Convert.ToDouble(txtYCoord.Text.Trim()) + ","; JSONToPatch += "\"" + pckType.AutomationId + "\":\"" + pckType.SelectedItem.ToString() + "\","; JSONToPatch += "\" Last Updated By \":\"" + current.localId + "\","; JSONToPatch = "{" + JSONToPatch.Substring(0, JSONToPatch.LastIndexOf(',')) + "}"; if (index > InfoStore.getDirectionNames().Count) { try { User currentUser = InfoStore.CurrentUser; string target = "https://airshowapp-d193b.firebaseio.com/Airshows/" + InfoStore.getAirshowIndex(InfoStore.Selected) + "/Directions/" + index.ToString() + ".json?auth=" + currentUser.token; ServicePointManager.ServerCertificateValidationCallback += (send, certificate, chain, sslPolicyErrors) => { return(true); }; Console.WriteLine("Patch note: " + JSONToPatch); WebClient client = new WebClient(); client.Headers[HttpRequestHeader.ContentType] = "application/json"; string rawResponse = client.UploadString(new Uri(target), "PUT", JSONToPatch); InfoStore.getDatabase(); LoadPage(new pgEditDirections()); } catch (Exception E) { Console.WriteLine(E.ToString()); App.Current.MainPage.DisplayAlert("Save Error", "There was an error saving this entry. Please try again", "OK"); LoadPage(new pgEditDirections()); } } else { try { // JSONToPatch = String.Concat(" ", JSONToPatch); User currentUser = InfoStore.CurrentUser; string target = "https://airshowapp-d193b.firebaseio.com/Airshows/" + InfoStore.getAirshowIndex(InfoStore.Selected) + "/Directions/" + index.ToString() + ".json?auth=" + currentUser.token; ServicePointManager.ServerCertificateValidationCallback += (send, certificate, chain, sslPolicyErrors) => { return(true); }; WebClient client = new WebClient(); client.Headers[HttpRequestHeader.ContentType] = "application/json"; Console.WriteLine("Patched: " + JSONToPatch); string rawResponse = client.UploadString(new Uri(target), "PATCH", JSONToPatch); Console.Write("Response is: " + rawResponse); InfoStore.getDatabase(); LoadPage(new pgEditDirections()); } catch (Exception E) { Console.WriteLine(E.ToString()); LoadPage(new pgEditDirections()); } } }