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<Response> ChanteToBob(bool ok) { try { using (HttpClient client = new HttpClient()) { client.BaseAddress = new Uri(URL.BASE); var definition = new { IsBob = ok }; var newObject = JsonConvert.SerializeObject(definition); HttpResponseMessage result = await client.PutAsync(URL.USER_CHANGETOBOB, new StringContent(newObject, Encoding.UTF8, "application/json")); string json = await result.Content.ReadAsStringAsync(); Response data = JsonConvert.DeserializeObject<Response>(json); return data; } } catch (JsonException jex) { return new Response() { Error = "Parse Error: " + jex.ToString(), Success = false }; } catch (Exception ex) { return new Response() { Error = ex.Message.ToString(), Success = false }; } }
public static async Task<Response> PostPoint(int rating) { try { using (HttpClient client = new HttpClient()) { client.BaseAddress = new Uri(URL.BASE); var definition = new { PointsDescription_ID = rating }; var newObject = JsonConvert.SerializeObject(definition); HttpResponseMessage result = await client.PostAsync(URL.USER_POINTS, new StringContent(newObject, Encoding.UTF8, "application/json")); string json = await result.Content.ReadAsStringAsync(); Response data = JsonConvert.DeserializeObject<Response>(json); return data; } } catch (JsonException jex) { return new Response() { Error = "Parse Error: " + jex.ToString(), Success = false }; } catch (Exception ex) { return new Response() { Error = ex.Message.ToString(), Success = false }; } }