public async Task<List<Contact>> SyncContacts(User user, List<Contact> contacts) { HttpStringContent postContent = new HttpStringContent(JsonConvert.SerializeObject(contacts)); postContent.Headers["Content-Type"] = "application/json"; try { string path = string.Format("/api/v1/users/{0}/contacts/sync", user.Id); HttpResponseMessage response = await client.PostAsync( new Uri(serviceUrl, path), postContent); if (response.IsSuccessStatusCode) { string content = await response.Content.ReadAsStringAsync(); List<Contact> syncedContacts = JsonConvert.DeserializeObject<List<Contact>>(content); return syncedContacts; } } catch { } return null; }
public void LoadData() { try { string data = (String) preferences["user"]; User = JsonConvert.DeserializeObject<User>(data); } catch(Exception e) { User = null; } }
public async Task<List<Contact>> LoadContacts(User user) { string path = string.Format("/api/v1/users/{0}/contacts", user.Id); HttpResponseMessage response = await client.GetAsync( new Uri(serviceUrl, path)); try { if (response.IsSuccessStatusCode) { string content = await response.Content.ReadAsStringAsync(); List<Contact> contacts = JsonConvert.DeserializeObject<List<Contact>>(content); return contacts; } } catch { } return null; }