public static async Task <bool> UpdateSavedThreadList() { try { SavedThreads = new ObservableCollection <Thread>(); string response = await request.Post("/getsaves", null, Authentication.Email, Authentication.Password); if (response == "Unauthorized Access") { Authentication.AuthenticationError(); return(false); } if (response == "error" || response == "")//this needs to be made simpler { return(false); } else { Dictionary <string, Dictionary <string, string> > values = JsonConvert.DeserializeObject <Dictionary <string, Dictionary <string, string> > >(response); foreach (var val in values) { Thread thread = new Thread(val.Value["title"], val.Value["username"], null, val.Value["description"], "", 0, Int32.Parse(val.Key)); SavedThreads.Add(thread); } return(true); } } catch { return(false); } }
public static async Task <bool> PostNewThread(Dictionary <string, string> data) { string response = await request.Post("/getcreatethread", data, Authentication.Email, Authentication.Password, ""); if (response == "Unauthorized Access") { Authentication.AuthenticationError(); return(false); } return(response == "posted"); }
public static async Task <bool> UpdateReports() { ReportList.Add(new Crop("Corn2", "Aphid", "High Risk", "Based on public data in area and weather data")); try { ReportList = new ObservableCollection <Report>(); //string response = ""; string response = await request.Post("/getreports", null, Authentication.Email, Authentication.Password); if (response == "Unauthorized Access") { Authentication.AuthenticationError(); return(false); } if (response == "invalid")//this needs to be made simpler { return(false); } if (response == "empty") { return(true); } else { Dictionary <string, Dictionary <string, string> > values = JsonConvert.DeserializeObject <Dictionary <string, Dictionary <string, string> > >(response); foreach (var val in values) { if (val.Key.Split(',')[0] == "crop") { Crop crop = new Crop(val.Value["problem"], val.Value["title"], val.Value["warning"], val.Value["description"]); ReportList.Add(crop); } if (val.Key.Split(',')[0] == "livestock") { LiveStock livestock = new LiveStock(val.Value["problem"], val.Value["title"], val.Value["warning"], val.Value["description"]); ReportList.Add(livestock); } if (val.Key.Split(',')[0] == "weather") { Weather weather = new Weather(val.Value["problem"], val.Value["title"], val.Value["warning"], val.Value["description"]); ReportList.Add(weather); } } return(true); } } catch { return(false); } }
public static async Task <string> GetThread(int id) { Dictionary <string, string> data = new Dictionary <string, string>(); data["thread_id"] = id.ToString(); string response = await request.Post("/getthread", data, Authentication.Email, Authentication.Password); if (response == "Unauthorized Access") { Authentication.AuthenticationError(); return("error"); } return(response); }
public static async Task <bool> RemoveSavedThread(Thread thread) { Dictionary <string, string> data = new Dictionary <string, string>(); data["thread_id"] = thread.ID.ToString(); string response = await request.Post("/getunsavethread", data, Authentication.Email, Authentication.Password); if (response == "Unauthorized Access") { Authentication.AuthenticationError(); return(false); } if (response == "unsaved") { SavedThreads.Remove(thread); return(true); } return(false); }
//Updates the thread list public static async Task <bool> UpdateThreads() { try { ThreadList = new ObservableCollection <Thread>(); string response = await request.Post("/getthreadlist", null, Authentication.Email, Authentication.Password); if (response == "Unauthorized Access") { Authentication.AuthenticationError(); return(false); } if (response == "invalid" || response == "")//this needs to be made simpler { return(false); } if (response == "empty")//this needs to be made simpler { return(true); } else { Dictionary <string, Dictionary <string, string> > values = JsonConvert.DeserializeObject <Dictionary <string, Dictionary <string, string> > >(response); foreach (var val in values) { Thread thread = new Thread(val.Value["title"], val.Value["username"], val.Value["image"], val.Value["description"], "", 0, Int32.Parse(val.Key)); //thread.PhotoSource = "http://" + Request.address + "/getimage/" + val.Key; ThreadList.Add(thread); } return(true); } } catch { return(false); } }
public static async Task <bool> UpdateFarmProfile() { FarmProfile = new ObservableCollection <FarmInfo>(); try { FarmProfile = new ObservableCollection <FarmInfo>(); string response = await request.Post("/getprofile", null, Authentication.Email, Authentication.Password); if (response == "Unauthorized Access") { Authentication.AuthenticationError(); return(false); } if (response == "invalid" || response == "error")//this needs to be made simpler { return(false); } else { Dictionary <string, Dictionary <string, string> > values = JsonConvert.DeserializeObject <Dictionary <string, Dictionary <string, string> > >(response); foreach (var val in values) { FarmInfo info = new FarmInfo(val.Value["name"], val.Value["type"], new Tuple <double, double>(double.Parse(val.Value["x"]), double.Parse(val.Value["y"])), val.Value["size"]); FarmProfile.Add(info); } return(true); } } catch { return(false); } }