public static void saveEvents() { Preferences.Set("tempMatchEvents", JsonConvert.SerializeObject(MatchFormat.eventsListToJSONEvents(NewMatchStart.events))); MatchEvents.update = true; }
//Checks if all neccesary Items exist, clears match data, and goes to Matches Page async void saveClicked(object sender, System.EventArgs e) { Entry.team = teamName; onParamUpdate(); if (popErrorsToScreen()) { } else { await Task.Run(async() => { Device.BeginInvokeOnMainThread(() => { //Disables save button so app doesn't crash when user taps many times saveButton.IsEnabled = false; }); //Gets and combines all of the match's events to a JObject JObject events = MatchFormat.eventsListToJSONEvents(NewMatchStart.events); events.Add("timerValue", NewMatchStart.timerValue); JObject parameters = JObject.FromObject(Entry); parameters.Merge(events); //Adds or creates new JObject to start all data in app cache JObject dataMain = initializeEventsObject(); JObject data = (JObject)dataMain[Preferences.Get(ConstantVars.CURRENT_EVENT_NAME, "")]; if (data.Count <= 0 || !data.ContainsKey("Matches")) { data.Add(new JProperty("Matches", new JArray())); pushBackToHome(dataMain, data, new JArray(), parameters); } else { JArray temp = (JArray)data["Matches"]; if (temp.ToList().Exists(x => x["matchNum"].Equals(parameters["matchNum"]) && x["side"].Equals(parameters["side"]))) { var item = temp.ToList().Find(x => x["matchNum"].Equals(parameters["matchNum"]) && x["side"].Equals(parameters["side"])); if (!item["team"].Equals(parameters["team"])) { Device.BeginInvokeOnMainThread(async() => { bool remove = await DisplayAlert("Error", "Overwrite Old Match with New Data?", "No", "Yes"); if (!remove) { temp.Remove(item); pushBackToHome(dataMain, data, temp, parameters); } else { saveButton.IsEnabled = true; return; } }); } else { temp.Remove(item); pushBackToHome(dataMain, data, temp, parameters); } } else { pushBackToHome(dataMain, data, temp, parameters); } } }); } }