private IEnumerator save() { string dummyString = "dummy"; //Creating JSON JObject locations = new JObject(); foreach (string s in tours) { locations[s] = dummyString; } string jsonData = locations.ToString(); if (TourNameText.text == "") { ErrorMessage.text = "Please enter Tour Name!"; ErrorPanel.SetActive(true); } var deleteTask = reference.Child(dbDetails.getTourDBName()).Child(TourNameText.text).SetValueAsync(null); yield return(new WaitUntil(predicate: () => deleteTask.IsCompleted)); if (deleteTask.Exception != null) { throw new Exception("ERROR while deleting values from database."); } else { var appendTask = reference.Child(dbDetails.getTourDBName()).Child(TourNameText.text).SetRawJsonValueAsync(jsonData); yield return(new WaitUntil(predicate: () => appendTask.IsCompleted)); if (appendTask.Exception != null) { throw new Exception("ERROR while appending values from database."); } else { Debug.Log("SUCCESS: DATA ADDED TO DATABASE"); } }; SceneManager.LoadScene("ManagerTourView"); }
void getScheduleData() { reference.GetValueAsync().ContinueWith(task => { if (task.IsFaulted) { // Handle the error... Debug.Log("error fetching data"); } else if (task.IsCompleted) { // getting schedules for a particular user. DataSnapshot snapshot = task.Result.Child(dbDetails.getTourDBName()); string str = snapshot.GetRawJsonValue(); JObject jsonLocation = JObject.Parse(str); IList <string> keys = jsonLocation.Properties().Select(p => p.Name).ToList(); foreach (string key in keys) { Debug.Log(key); this.schedules.Add(new Department(key)); } } }); }
public void onDelete() { // write delete logic here DB_Details dbDetails = new DB_Details(); // Set up the Editor before calling into the realtime database. FirebaseApp.DefaultInstance.SetEditorDatabaseUrl(dbDetails.getDBUrl()); // Get the root reference location of the database. DatabaseReference reference = FirebaseDatabase.DefaultInstance.RootReference; reference.Child(dbDetails.getTourDBName()).Child(Name.text).RemoveValueAsync().ContinueWith(task => { if (task.IsFaulted) { Debug.Log("ERROR: when accessing Data from Database"); } else if (task.IsCompleted) { Debug.Log("SUCCESS: DATA Deleted IN DATABASE"); } }); item.Destroy(); deletePanel.SetActive(false); }
public void onSave() { //Creating JSON JObject locations = new JObject(); JObject time = new JObject(); foreach (LocationWithTime location in this.locations) { locations.Add(location.Name, location.Time); // time["Time"] = location.Time; // locations[location.Name] = time; } string jsonData = locations.ToString(); try { if (ScheduleNameText.text == "") { throw new Exception("Please enter Tour Name!"); } //Temp until authentication is completed Singleton singleton = Singleton.Instance(); String user = singleton.getUserName(); //String user = "******"; reference.Child(dbDetails.getTourDBName()).Child(user).Child(ScheduleNameText.text).RemoveValueAsync(); reference.Child(dbDetails.getScheduleDBName()).Child(user).Child(ScheduleNameText.text).SetRawJsonValueAsync(jsonData).ContinueWith(task => { if (task.IsFaulted) { throw new Exception("ERROR while appending values to database."); } else if (task.IsCompleted) { Debug.Log("SUCCESS: DATA ADDED TO DATABASE"); } }); SceneManager.LoadScene("SchedulesScene"); } catch (InvalidCastException e) { // Perform some action here, and then throw a new exception. ErrorMessage.text = e.Message; ErrorPanel.SetActive(true); } catch (Exception e) { // Perform some action here, and then throw a new exception. ErrorMessage.text = e.Message; ErrorPanel.SetActive(true); } }
void getTourData() { try { reference.GetValueAsync().ContinueWith(task => { if (task.IsFaulted) { throw new Exception("ERROR while fetching data from database!!! Please refresh scene(Click Tours)"); } else if (task.IsCompleted) { DataSnapshot snapshot = task.Result.Child(dbDetails.getTourDBName()).Child(TourName); string str = snapshot.GetRawJsonValue(); JObject jsonLocation = JObject.Parse(str); IList <string> keys = jsonLocation.Properties().Select(p => p.Name).ToList(); foreach (string key in keys) { Debug.Log(key); this.tours.Add(key); } } }); } catch (InvalidCastException e) { // Perform some action here, and then throw a new exception. ErrorMessage.text = e.Message; ErrorPanel.SetActive(true); } catch (Exception e) { // Perform some action here, and then throw a new exception. ErrorMessage.text = e.Message; ErrorPanel.SetActive(true); } }
void getLocationData() { PSLocationArraySingleton ps = PSLocationArraySingleton.Instance(); Singleton s = Singleton.Instance(); string scheduleName = s.getTourName(); locationsTemp.Clear(); DepartmentTour.text = scheduleName + " Locations"; reference.GetValueAsync().ContinueWith(task => { if (task.IsFaulted) { // Handle the error... Debug.Log("error fetching data"); } else if (task.IsCompleted) { // getting schedules for a particular user. snapshot = task.Result.Child(dbDetails.getTourDBName()).Child(scheduleName.ToString()); string str = snapshot.GetRawJsonValue(); JObject jsonLocation = JObject.Parse(str); IList <string> keys = jsonLocation.Properties().Select(p => p.Name).ToList(); foreach (string key in keys) { this.locations.Add(new DeptLocation(key)); } Dictionary <string, ArrayList> toursLocations = ps.getToursLocationDictionary(); ArrayList updatedLocations = toursLocations[scheduleName]; if (updatedLocations == null) { toursLocations[scheduleName] = locationsTemp; } } }); }
void getTourData() { try { reference.GetValueAsync().ContinueWith(task => { if (task.IsFaulted) { throw new Exception("ERROR while fetching data from database!!! Please refresh scene(Click Tours)"); } else if (task.IsCompleted) { DataSnapshot snapshot = task.Result.Child(dbDetails.getTourDBName()).Child(TourName); Dictionary <string, object> locationData = JsonConvert.DeserializeObject <Dictionary <string, object> >(snapshot.GetRawJsonValue()); int i = 0; foreach (string location in locationData.Keys) { locations.Add(new TourLocation(location, i + 1)); i++; } getCoordinates(); } }); } catch (InvalidCastException e) { // Perform some action here, and then throw a new exception. ErrorMessage.text = e.Message; ErrorPanel.SetActive(true); } catch (Exception e) { // Perform some action here, and then throw a new exception. ErrorMessage.text = e.Message; ErrorPanel.SetActive(true); } }