Exemple #1
0
        public static void getDatabase()
        {
            InfoStore.Clear();
            statusOptions.Clear();
            statusOptions.Add("Preparing");
            statusOptions.Add("On-Deck");
            statusOptions.Add("In-Air");
            statusOptions.Add("Completed");


            string target = "https://airshowapp-d193b.firebaseio.com/.json?auth=" + InfoStore.CurrentUser.token;

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

            try
            {
                WebClient client = new WebClient();
                client.Headers[HttpRequestHeader.ContentType] = "application/json";
                string rawResponse = client.DownloadString(new Uri(target));
                Console.WriteLine(rawResponse);
                database = Database.FromJson(rawResponse);;
            }
            catch (Exception E)
            {
                Console.WriteLine(E.ToString());
            }
        }
Exemple #2
0
        private void lostFocus(object sender, EventArgs e)
        {
            Entry snt = (Entry)sender;

            Console.WriteLine("Unfocusing: " + snt.AutomationId);
            int selectedIndex = InfoStore.getAirshowIndex(InfoStore.Selected);


            if (validate(snt))
            {
                JSONToPatch += "\"" + snt.AutomationId + "\":" + "\"" + snt.Text.Trim() + "\",";
                if (badEntries.Contains(snt.AutomationId))
                {
                    badEntries.Remove(snt.AutomationId);
                }
                readyToSend = true;
            }
            else if (!readyToSend)
            {
            }
            else
            {
                if (!badEntries.Contains(snt.AutomationId))
                {
                    badEntries.Add(snt.AutomationId);
                }
            }
        }
        private void performSave()
        {
            string JSONToPatch = "";

            JSONToPatch += "\"" + txtName.AutomationId + "\":\"" + txtName.Text.Trim() + "\",";
            JSONToPatch += "\"" + txtDesc.AutomationId + "\":\"" + txtDesc.Text.Trim() + "\",";

            JSONToPatch = "{" + JSONToPatch.Substring(0, JSONToPatch.LastIndexOf(','));

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

            if (index > InfoStore.getFoodNames().Count)
            {
                try
                {
                    User   currentUser = InfoStore.CurrentUser;
                    string target      = "https://airshowapp-d193b.firebaseio.com/Airshows/" + InfoStore.getAirshowIndex(InfoStore.Selected) + "/Foods/" + 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 pgEditFoods());
                }
                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) + "/Foods/" + 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 pgEditFoods());
                }
                catch (Exception E)
                {
                    Console.WriteLine(E.ToString());
                }
            }
        }
        public AddOrEditFoodView(string selectedFoodName, int fooIndex)
        {
            InitializeComponent();
            index = fooIndex;
            Food selected = InfoStore.getFoodByName(selectedFoodName);

            txtDesc.Text = selected.Description;
            txtName.Text = selected.Name;
        }
Exemple #5
0
        public static List <string> getPerformerNames()
        {
            List <string> Names = new List <string>();

            foreach (Performer perf in Database.Airshows[InfoStore.getAirshowIndex(InfoStore.Selected)].Performers)
            {
                Names.Add(perf.Name);
            }
            return(Names);
        }
Exemple #6
0
        public static List <string> getFoodNames()
        {
            List <string> Foods = new List <string>();

            foreach (Food foo in Database.Airshows[InfoStore.getAirshowIndex(InfoStore.Selected)].Foods)
            {
                Foods.Add(foo.Name);
            }
            return(Foods);
        }
Exemple #7
0
        public addOrEditStatics(string selectedStaticName, int staticIndex)
        {
            InitializeComponent();
            index = staticIndex;
            Static selected = InfoStore.getStaticByName(selectedStaticName);

            txtDesc.Text  = selected.Description;
            txtName.Text  = selected.Name;
            txtImage.Text = selected.Image;
        }
Exemple #8
0
        public static List <string> getDirectionNames()
        {
            List <string>    Names      = new List <string>();
            List <Direction> directions = Database.Airshows[InfoStore.getAirshowIndex(InfoStore.Selected)].Directions ?? new List <Direction>();

            foreach (Direction dir in directions)
            {
                Names.Add(dir.Name);
            }
            return(Names);
        }
 public AddOrEditPerformerView(string selectedPerformerName, int perfIndex)
 {
     InitializeComponent();
     index = perfIndex;
     pckInAir.ItemsSource  = InfoStore.statusOptions;
     selected              = InfoStore.getPerformerByName(selectedPerformerName);
     txtDesc.Text          = selected.Description;
     txtImage.Text         = (selected.Image == "")? "https://i.imgur.com/mXv4hUL.png" : selected.Image;
     txtName.Text          = selected.Name;
     txtSchedule.Text      = selected.OrderNumber.ToString();
     pckInAir.SelectedItem = selected.InAir;
 }
Exemple #10
0
        public static List <string> getStaticNames()
        {
            List <string> names = new List <string>();

            foreach (Static stat in Database.Airshows[InfoStore.getAirshowIndex(InfoStore.Selected)].Statics)
            {
                if (stat.Name != null)
                {
                    names.Add(stat.Name);
                }
            }
            return(names.Count >= 1 ? names : null);
        }
Exemple #11
0
        public AddOrEditDirectionsView(string selectedDirectionName, int directIndex)
        {
            InitializeComponent();
            fullPick();
            typePick();
            index = directIndex;
            Direction selected = InfoStore.getDirectionByName(selectedDirectionName);

            pckFull.SelectedItem = selected.Full.ToString();
            pckType.SelectedItem = selected.Type.ToString();
            txtName.Text         = selected.Name;
            txtXCoord.Text       = selected.XCoord.ToString();
            txtYCoord.Text       = selected.YCoord.ToString();
        }
Exemple #12
0
        private void deleteStatics(object sender, EventArgs e)
        {
            InfoStore.getDatabase();

            if (Database.Airshows[InfoStore.getAirshowIndex(InfoStore.Selected)].Statics.Count > 1)
            {
                performDelete();
            }
            else
            {
                App.Current.MainPage = new pgEditStatics();
                App.Current.MainPage.DisplayAlert("Delete Error", "There must be at least one static display stored. Please add another before attempting to delete one.", "OK");
            }
        }
 public pgEditFoods()
 {
     InitializeComponent();
     btnBack = (Button)myStackLayout.Children[2];
     foreach (string name in InfoStore.getFoodNames())
     {
         pckFoods.Items.Add(name);
     }
     pckFoods.Items.Add("Add New Food");
     if (Device.RuntimePlatform == Device.Android)
     {
         backButton.IsVisible = false;
     }
 }
Exemple #14
0
        public static Static getStaticByName(string staticName)
        {
            int intIndex = 0;

            foreach (Static stat in Database.Airshows[InfoStore.getAirshowIndex(InfoStore.Selected)].Statics)
            {
                if (stat.Name == staticName)
                {
                    staticIndex = intIndex;
                    return(stat);
                }
                intIndex++;
            }
            return(new Static("", "", ""));
        }
Exemple #15
0
        public static Performer getPerformerByName(string performerName)
        {
            int intIndex = 0;

            foreach (Performer perf in Database.Airshows[InfoStore.getAirshowIndex(InfoStore.Selected)].Performers)
            {
                if (perf.Name == performerName)
                {
                    performerIndex = intIndex;
                    return(perf);
                }
                intIndex++;
            }
            return(new Performer("", "", "Preparing", "", Convert.ToString(Database.Airshows[InfoStore.getAirshowIndex(InfoStore.Selected)].Performers.Count + 1)));
        }
 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;
     }
 }
Exemple #17
0
        public static Food getFoodByName(string foodName)
        {
            int intIndex = 0;

            foreach (Food foo in Database.Airshows[InfoStore.getAirshowIndex(InfoStore.Selected)].Foods)
            {
                if (foo.Name == foodName)
                {
                    foodIndex = intIndex;
                    return(foo);
                }
                intIndex++;
            }
            return(new Food("", ""));
        }
Exemple #18
0
        public static Direction getDirectionByName(string directionName)
        {
            int intIndex = 0;
            List <Direction> directions = Database.Airshows[(InfoStore.getAirshowIndex(InfoStore.Selected))].Directions ?? new List <Direction>();

            foreach (Direction dir in directions)
            {
                if (dir.Name == directionName)
                {
                    return(dir);
                }
                intIndex++;
            }
            return(new Direction(false, "", "", 0, 0));
        }
Exemple #19
0
 private void btnSave_Clicked(object sender, EventArgs e)
 {
     if (badEntries.Count > 0)
     {
         DisplayAlert("Save Error", "Ensure all entries are valid", "OK");
     }
     else if (JSONToPatch != null && JSONToPatch.Length > 0)
     {
         JSONToPatch  = "{" + JSONToPatch.Substring(0, JSONToPatch.LastIndexOf(','));
         JSONToPatch += ",\" Last Updated By \":\"" + current.localId + "\"" + "}";
         sendPatch();
         JSONToPatch = "";
         readyToSend = false;
         InfoStore.getDatabase();
     }
 }
Exemple #20
0
        private void performDelete()
        {
            string toWrite      = "";
            Static statToDelete = new Static("", "", "");

            foreach (Static stat in Database.Airshows[InfoStore.getAirshowIndex(InfoStore.Selected)].Statics)
            {
                if (stat.Name == txtName.Text.Trim())
                {
                    statToDelete = stat;
                }
            }
            try
            {
                Database.Airshows[InfoStore.getAirshowIndex(InfoStore.Selected)].Statics.Remove(statToDelete);
                toWrite = JsonConvert.SerializeObject(Database.Airshows[InfoStore.getAirshowIndex(InfoStore.Selected)].Statics);
                Console.WriteLine(toWrite);
            }
            catch (Exception E)
            {
                App.Current.MainPage.DisplayAlert("Delete Error", "There was an error deleting this entry.  Make sure that no fields were changed and try again", "OK");
                Console.WriteLine(E.ToString());
                LoadPage(new pgEditStatics());
            }

            try
            {
                User   currentUser = InfoStore.CurrentUser;
                string target      = "https://airshowapp-d193b.firebaseio.com/Airshows/" + InfoStore.getAirshowIndex(InfoStore.Selected) + "/Statics/.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", toWrite);

                Console.Write("Response is: " + rawResponse);
                InfoStore.getDatabase();
                LoadPage(new pgEditStatics());
            }
            catch (Exception E)
            {
                App.Current.MainPage.DisplayAlert("Delete Error", "There was an error deleting this entry.  Make sure that no fields were changed and try again", "OK");

                Console.WriteLine(E.ToString());
            }
        }
        private void performDelete()
        {
            string    toWrite      = "{\"Performers\":";
            Performer perfToDelete = new Performer("", "", "", "", "1");

            foreach (Performer perf in Database.Airshows[aSIndex].Performers)
            {
                if (perf.Name.Trim() == txtName.Text.Trim())
                {
                    perfToDelete = perf;
                }
            }
            try
            {
                Database.Airshows[aSIndex].Performers.Remove(perfToDelete);
                toWrite += JsonConvert.SerializeObject(Database.Airshows[aSIndex].Performers);
                Console.WriteLine(toWrite);
            }
            catch (Exception E)
            {
                Console.WriteLine(E.ToString());
            }

            try
            {
                toWrite += "}";
                User   currentUser = InfoStore.CurrentUser;
                string target      = "https://airshowapp-d193b.firebaseio.com/Airshows/" + InfoStore.getAirshowIndex(InfoStore.Selected) + "/.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), "PATCH", toWrite);
                JObject response    = JObject.Parse(rawResponse);

                Console.Write("Response is: " + rawResponse);
                InfoStore.getDatabase();
                LoadPage(new pgEditPerformers());
            }
            catch (Exception E)
            {
                Console.WriteLine(E.ToString());
            }
        }
Exemple #22
0
 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");
     }
 }
Exemple #23
0
        private void performDelete()
        {
            string    toWrite     = "";
            Direction dirToDelete = new Direction(false, "", "", 0, 0);

            foreach (Direction dir in Database.Airshows[InfoStore.getAirshowIndex(InfoStore.Selected)].Directions)
            {
                if (dir.Name == txtName.Text.Trim())
                {
                    dirToDelete = dir;
                }
            }
            try
            {
                Database.Airshows[InfoStore.getAirshowIndex(InfoStore.Selected)].Directions.Remove(dirToDelete);
                toWrite = JsonConvert.SerializeObject(Database.Airshows[InfoStore.getAirshowIndex(InfoStore.Selected)].Directions);
            }
            catch (Exception E)
            {
                Console.WriteLine(E.ToString());
            }

            try
            {
                User   currentUser = InfoStore.CurrentUser;
                string target      = "https://airshowapp-d193b.firebaseio.com/Airshows/" + InfoStore.getAirshowIndex(InfoStore.Selected) + "/Directions/.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", toWrite);

                Console.Write("Response is: " + rawResponse);
                InfoStore.getDatabase();
                LoadPage(new pgEditDirections());
            }
            catch (Exception E)
            {
                Console.WriteLine(E.ToString());
            }
        }
Exemple #24
0
        private void btnLogin_Clicked(object sender, EventArgs e)
        {
            NavigationPage navPage  = new NavigationPage(this);
            IList <View>   children = loginStackLayout.Children;


            if (txtUsername.Text.Trim() != "" && txtPass.Text.Trim() != "")
            {
                if (Login(txtUsername.Text, txtPass.Text))
                {
                    InfoStore.getDatabase();
                    App.Current.MainPage = new pgSelectOrCreate();
                }
                else
                {
                    DisplayAlert("Login Invalid", "Input correct credentials", "OK");
                    txtPass.Text     = "";
                    txtUsername.Text = "";
                }
            }
        }
Exemple #25
0
        //This works because I created a list of entries^^. Everytime a new entry is made I add it to the list. Now we can Foreach them easily
        //I interate through the list and find all the entries that have the same autoID as the sender button
        //Then I create a string for every entry that matches and add the string to the JSONToPatch string
        //So the save buttons send a patch for every child of the specific performer that has the same index as their autoID... not best practice but it works
        private void sendPatch(object sender, EventArgs e)
        {
            Button btnSender = (Button)sender;

            string strIndex = btnSender.AutomationId;

            string JSONToPatch = "";

            foreach (View v in entries)
            {
                if (v.GetType() == typeof(Entry))
                {
                    Entry ent = v as Entry;
                    if (ent.AutomationId.Split('.')[1] == strIndex)
                    {
                        JSONToPatch += "\"" + ent.AutomationId.Split('.')[0] + "\":\"" + ent.Text.Trim() + "\",";
                    }
                }
                else if (v.GetType() == typeof(Editor))
                {
                    Editor edt = v as Editor;
                    if (edt.AutomationId.Split('.')[1] == strIndex)
                    {
                        JSONToPatch += "\"" + edt.AutomationId.Split('.')[0] + "\":\"" + edt.Text.Trim() + "\",";
                    }
                }
                else if (v.GetType() == typeof(Picker))
                {
                    Picker pck = v as Picker;
                    if (pck.AutomationId.Split('.')[1] == strIndex)
                    {
                        JSONToPatch += "\"" + pck.AutomationId.Split('.')[0] + "\":\"" + pck.SelectedItem.ToString() + "\",";
                    }
                }
            }
            JSONToPatch = "{" + JSONToPatch.Substring(0, JSONToPatch.LastIndexOf(',')) + "}";

            try
            {
                User   currentUser = InfoStore.CurrentUser;
                string target      = "https://airshowapp-d193b.firebaseio.com/Airshows/" + InfoStore.getAirshowIndex(InfoStore.Selected) + "/Performers/" + btnSender.AutomationId + ".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), "PATCH", JSONToPatch);
                JObject response    = JObject.Parse(rawResponse);

                Console.Write("Response is: " + rawResponse);
            }
            catch (Exception E)
            {
                Console.WriteLine(E.ToString());
            }
        }
Exemple #26
0
        private void sendPatch()
        {
            try
            {
                User   currentUser = InfoStore.CurrentUser;
                string target      = "https://airshowapp-d193b.firebaseio.com/Airshows/" + InfoStore.getAirshowIndex(InfoStore.Selected) + "/.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), "PATCH", JSONToPatch);
                JObject response    = JObject.Parse(rawResponse);

                Console.Write("Response is: " + rawResponse);
                readyToSend = false;
            }
            catch (Exception E)
            {
                Console.WriteLine(E.ToString());
            }
        }
        private void performSave()
        {
            try
            {
                string JSONToPatch = "{";

                OrderPerformers();

                //JSONToPatch = JsonConvert.SerializeObject(Database.Airshows[aSIndex].Performers);

                IList <Entry> entries = new List <Entry>();
                foreach (View v in stkLayout.Children)
                {
                    if (v.GetType() == typeof(Entry))
                    {
                        string textToAdd = "";
                        Entry  txtBox    = v as Entry;

                        if (txtBox.AutomationId == "Image" && txtBox.Text.Trim() == "")
                        {
                            textToAdd = "https://i.imgur.com/mXv4hUL.png";
                        }
                        else
                        {
                            textToAdd = txtBox.Text;
                        }
                        JSONToPatch += "\"" + txtBox.AutomationId + "\":\"" + textToAdd + "\",";
                    }
                    else if (v.GetType() == typeof(Editor))
                    {
                        Editor edit = v as Editor;
                        JSONToPatch += "\"" + edit.AutomationId + "\":\"" + edit.Text.Trim() + "\",";
                    }
                    else if (v.GetType() == typeof(Picker))
                    {
                        Picker pick = v as Picker;
                        JSONToPatch += "\"" + pick.AutomationId + "\":\"" + pick.SelectedItem.ToString() + "\",";
                    }
                }

                JSONToPatch = JSONToPatch.Substring(0, JSONToPatch.LastIndexOf(','));

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

                Console.WriteLine(JSONToPatch);

                User   currentUser = InfoStore.CurrentUser;
                string target      = "https://airshowapp-d193b.firebaseio.com/Airshows/" + aSIndex.ToString() + "/Performers/" + index + "/.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), "PATCH", JSONToPatch);

                Console.Write("Response is: " + rawResponse);
            }
            catch (Exception E) {
                Console.Write(E.ToString());
            }

            InfoStore.getDatabase();

            LoadPage(new pgEditPerformers());
        }
Exemple #28
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());
                }
            }
        }
Exemple #29
0
        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());
                }
            }
        }
        private void OrderPerformers()
        {
            Performer changed     = InfoStore.getPerformerByName(selected.Name);
            bool      newisHigher = (Convert.ToInt16(changed.OrderNumber) < Convert.ToInt16(txtSchedule.Text.Trim()));

            changed.OrderNumber = txtSchedule.Text.Trim();
            changed.Name        = txtName.Text.Trim();
            changed.Description = txtName.Text.Trim();
            changed.Image       = txtImage.Text.Trim();
            changed.InAir       = pckInAir.SelectedItem.ToString();

            if (index >= InfoStore.getPerformerNames().Count)
            {
                Database.Airshows[aSIndex].Performers.Add(changed);
            }
            else
            {
                Database.Airshows[aSIndex].Performers[index] = changed;
            }

            Database.Airshows[aSIndex].Performers = Database.Airshows[aSIndex].Performers.OrderBy(x => x.OrderNumber).ToList();


            if (!newisHigher)
            {
                for (int i = 1; i <= Database.Airshows[aSIndex].Performers.Count; i++)
                {
                    if (Convert.ToInt16(changed.OrderNumber) == Database.Airshows[aSIndex].Performers.Count && Database.Airshows[aSIndex].Performers[Database.Airshows[aSIndex].Performers.Count - 1] != changed)
                    {
                        Database.Airshows[aSIndex].Performers[Database.Airshows[aSIndex].Performers.Count - 2]             = Database.Airshows[aSIndex].Performers[Database.Airshows[aSIndex].Performers.Count - 1];
                        Database.Airshows[aSIndex].Performers[Database.Airshows[aSIndex].Performers.Count - 2].OrderNumber = Convert.ToString(Database.Airshows[aSIndex].Performers.Count - 1);
                        Database.Airshows[aSIndex].Performers[Database.Airshows[aSIndex].Performers.Count - 1]             = changed;
                    }
                    else if (!(changed.OrderNumber == Database.Airshows[aSIndex].Performers[i - 1].OrderNumber))
                    {
                        Database.Airshows[aSIndex].Performers[i - 1].OrderNumber = Convert.ToString(i);
                    }
                    else if (Database.Airshows[aSIndex].Performers[i - 1] == changed)
                    {
                        Database.Airshows[aSIndex].Performers[i - 1].OrderNumber = changed.OrderNumber;
                    }
                    else
                    {
                        Database.Airshows[aSIndex].Performers[i - 1].OrderNumber = Convert.ToString(++i);
                    }
                }
            }
            else
            {
                for (int i = 1; i <= Database.Airshows[aSIndex].Performers.Count; i++)
                {
                    if (!(changed.OrderNumber == Database.Airshows[aSIndex].Performers[i - 1].OrderNumber))
                    {
                        Database.Airshows[aSIndex].Performers[i - 1].OrderNumber = Convert.ToString(i);
                    }
                    else if (Database.Airshows[aSIndex].Performers[i - 1].Name == changed.Name)
                    {
                        Database.Airshows[aSIndex].Performers[i - 1].OrderNumber = changed.OrderNumber;
                    }
                    else
                    {
                        Database.Airshows[aSIndex].Performers[i - 1].OrderNumber = Convert.ToString(i - 1);
                    }
                }
            }
            Database.Airshows[aSIndex].Performers = Database.Airshows[aSIndex].Performers.OrderBy(x => x.OrderNumber).ToList();
        }