//string moet nog verandert worden public static async Task<Trip> GetCurrentTrip() { try { using (HttpClient client = new HttpClient()) { var result = client.GetAsync(URL.CURRENTTRIP); string json = await result.Result.Content.ReadAsStringAsync(); Trip data = JsonConvert.DeserializeObject<Trip>(json); return data; } } catch (JsonException jex) { Response res = new Response() { Error = "Parse Error: " + jex.ToString(), Success = false }; Debug.WriteLine(res); return null; } catch (Exception ex) { Response res = new Response() { Error = ex.Message.ToString(), Success = false }; Debug.WriteLine(res); return null; } }
public static async Task<Models.relations.Users_Destinations> GetDefaultDestination() { try { using (HttpClient client = new HttpClient()) { var result = client.GetAsync(URL.DESTINATIONS_DEFAULT); string json = await result.Result.Content.ReadAsStringAsync(); Models.relations.Users_Destinations data = JsonConvert.DeserializeObject<Models.relations.Users_Destinations>(json); return data; } } catch (JsonException jex) { Response res = new Response() { Error = "Parse Error: " + jex.ToString(), Success = false }; Debug.WriteLine(res); return null; } catch (Exception ex) { Response res = new Response() { Error = ex.Message.ToString(), Success = false }; Debug.WriteLine(res); return null; } }
public static async Task<string> GetTotalPoints() { try { using (HttpClient client = new HttpClient()) { var definition = new { Points = "" }; var result = client.GetAsync(URL.USER_POINTSAMOUNT); string json = await result.Result.Content.ReadAsStringAsync(); var data = JsonConvert.DeserializeAnonymousType(json, definition); return data.Points; } } catch (JsonException jex) { Response res = new Response() { Error = "Parse Error: " + jex.ToString(), Success = false }; Debug.WriteLine(res); return null; } catch (Exception ex) { Response res = new Response() { Error = ex.Message.ToString(), Success = false }; Debug.WriteLine(res); return null; } }
public static async Task<List<Autotype>> GetAutotypes() { try { using (HttpClient client = new HttpClient()) { var result = client.GetAsync(URL.AUTOTYPES); string json = await result.Result.Content.ReadAsStringAsync(); List<Autotype> data = JsonConvert.DeserializeObject<List<Autotype>>(json); return data; } } catch (JsonException jex) { Response res = new Response() { Error = "Parse Error: " + jex.ToString(), Success = false }; Debug.WriteLine(res); return null; } catch (Exception ex) { Response res = new Response() { Error = ex.Message.ToString(), Success = false }; Debug.WriteLine(res); return null; } }
public static async Task<Models.User.All> GetUserById(int id) { try { using (HttpClient client = new HttpClient()) { var result = client.GetAsync(URL.USERS + "/" + id.ToString()); string json = await result.Result.Content.ReadAsStringAsync(); Models.User.All data = JsonConvert.DeserializeObject<Models.User.All>(json); return data; } } catch (JsonException jex) { Response res = new Response() { Error = "Parse Error: " + jex.ToString(), Success = false }; Debug.WriteLine(res); return null; } catch (Exception ex) { Response res = new Response() { Error = ex.Message.ToString(), Success = false }; Debug.WriteLine(res); return null; } }
public static async Task<Models.User.All> GetUserByEmail(string email) { try { using (HttpClient client = new HttpClient()) { client.BaseAddress = new Uri(URL.BASE); var newObject = JsonConvert.SerializeObject(new { Email = email }); HttpResponseMessage result = await client.PostAsync(URL.USERS_FIND, new StringContent(newObject, Encoding.UTF8, "application/json")); string json = await result.Content.ReadAsStringAsync(); Models.User.All data = JsonConvert.DeserializeObject<Models.User.All>(json); return data; } } catch (JsonException jex) { Response res = new Response() { Error = "Parse Error: " + jex.ToString(), Success = false }; Debug.WriteLine(res); return null; } catch (Exception ex) { Response res = new Response() { Error = ex.Message.ToString(), Success = false }; Debug.WriteLine(res); return null; } }
public static async Task<Response> SetOffer(bool active, int bobs_ID) { try { using (HttpClient client = new HttpClient()) { client.BaseAddress = new Uri(URL.BASE); var definition = new { Active= active, Bobs_ID= bobs_ID}; var newObject = JsonConvert.SerializeObject(definition); HttpResponseMessage result = await client.PutAsync(URL.BOBS_ACTIVE, new StringContent(newObject, Encoding.UTF8, "application/json")); string json = await result.Content.ReadAsStringAsync(); Response data = JsonConvert.DeserializeObject<Response>(json); return data; } } catch (JsonException jex) { Response res = new Response() { Error = "Parse Error: " + jex.ToString(), Success = false }; Debug.WriteLine(res); return null; } catch (Exception ex) { Response res = new Response() { Error = ex.Message.ToString(), Success = false }; Debug.WriteLine(res); return null; } }
public static async Task<List<Bob>> FindBobs(int? rating, DateTime minDate, int BobsType_ID, Location location, int? maxDistance) { try { using (HttpClient client = new HttpClient()) { client.BaseAddress = new Uri(URL.BASE); var definition = new { Rating = rating, MinDate = minDate, BobsType_ID = BobsType_ID, Location = JsonConvert.SerializeObject(location), MaxDistance = maxDistance }; var newObject = JsonConvert.SerializeObject(definition); HttpResponseMessage result = await client.PostAsync(URL.BOBS_FIND, new StringContent(newObject, Encoding.UTF8, "application/json")); string json = await result.Content.ReadAsStringAsync(); List<Bob> data = JsonConvert.DeserializeObject<List<Bob>>(json); return data; } } catch (JsonException jex) { Response res = new Response() { Error = "Parse Error: " + jex.ToString(), Success = false }; Debug.WriteLine(res); return null; } catch (Exception ex) { Response res = new Response() { Error = ex.Message.ToString(), Success = false }; Debug.WriteLine(res); return null; } }
public static async Task<Models.Location> GetLocation() { try { using (HttpClient client = new HttpClient()) { var definition = new {Location = Location.Current, Added = "" }; var result = client.GetAsync(URL.USER_LOCATION); string json = await result.Result.Content.ReadAsStringAsync(); var data = JsonConvert.DeserializeAnonymousType(json, definition); Location location = data.Location as Location; return location; } } catch (JsonException jex) { Response res = new Response() { Error = "Parse Error: " + jex.ToString(), Success = false }; Debug.WriteLine(res); return null; } catch (Exception ex) { Response res = new Response() { Error = ex.Message.ToString(), Success = false }; Debug.WriteLine(res); return null; } }
public static async Task<List<Party>> GetPartiesInArea(string location, double distance) { try { using (HttpClient client = new HttpClient()) { client.BaseAddress = new Uri(URL.PARTIES_AREA); var newObject = JsonConvert.SerializeObject(new { Location = location, Distance = distance }); HttpResponseMessage result = await client.PostAsync(URL.PARTIES_AREA, new StringContent(newObject, Encoding.UTF8, "application/json")); string json = await result.Content.ReadAsStringAsync(); List<Party> data = JsonConvert.DeserializeObject<List<Party>>(json); return data; } } catch (JsonException jex) { Response res = new Response() { Error = "Parse Error: " + jex.ToString(), Success = false }; Debug.WriteLine(res); return null; } catch (Exception ex) { Response res = new Response() { Error = ex.Message.ToString(), Success = false }; Debug.WriteLine(res); return null; } }
public static async Task<List<Users_PointsDescription>> GetDescription() { try { using (HttpClient client = new HttpClient()) { var result = client.GetAsync(URL.USER_POINTS_DESCRIPTION); string json = await result.Result.Content.ReadAsStringAsync(); List<Users_PointsDescription> data = JsonConvert.DeserializeObject<List<Users_PointsDescription>>(json); return data; } } catch (JsonException jex) { Response res = new Response() { Error = "Parse Error: " + jex.ToString(), Success = false }; Debug.WriteLine(res); return null; } catch (Exception ex) { Response res = new Response() { Error = ex.Message.ToString(), Success = false }; Debug.WriteLine(res); return null; } }