/// <summary> /// Retrieves tutorings for current user /// </summary> /// <returns>List of user's tutorings</returns> public async Task <List <MyTutoring> > GetMyTutorings() { var auth = new RestCommandWithAuthentication { authentication = MvvmNanoIoC.Resolve <Authentication>() }; _restUrl = "http://tutorscout24.vogel.codes:3000/tutorscout24/api/v1/tutoring/my"; if (MasterDetailViewModel.CurrentMode.Equals(MasterDetailViewModel.Mode.STUDENT)) { _restUrl += "Requests"; } else { _restUrl += "Offers"; } var uri = new Uri(string.Format(_restUrl, string.Empty)); var json = JsonConvert.SerializeObject(auth); var content = new StringContent(json, Encoding.UTF8, "application/json"); Debug.WriteLine(json); var response = await _client.PostAsync(uri, content); Debug.WriteLine("Response:" + await response.Content.ReadAsStringAsync()); if (response.IsSuccessStatusCode) { var rescontent = await response.Content.ReadAsStringAsync(); return(JsonConvert.DeserializeObject <List <MyTutoring> >(rescontent)); } return(null); }
///<summary> /// Update User /// </summary> /// <param name="cmd">Authentication</param> /// <returns>true if successfull, false otherwise</returns> public async Task <bool> UpdateUser(RestCommandWithAuthentication cmd) { cmd.authentication = MvvmNanoIoC.Resolve <Authentication>(); _restUrl = "http://tutorscout24.vogel.codes:3000/tutorscout24/api/v1/user/updateUser"; var uri = new Uri(string.Format(_restUrl, string.Empty)); var json = JsonConvert.SerializeObject(cmd, Formatting.None, new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore }); var content = new StringContent(json, Encoding.UTF8, "application/json"); Debug.WriteLine(json); HttpResponseMessage response = null; response = await _client.PutAsync(uri, content); Debug.WriteLine(await response.Content.ReadAsStringAsync()); return(response.IsSuccessStatusCode); }
///<summary> /// Get sent messages for currently logged in user /// </summary> /// <returns>List of RestMessages that the user has sent.</returns> public async Task <List <RestMessage> > GetSentMessages() { var cmd = new RestCommandWithAuthentication(); cmd.authentication = MvvmNanoIoC.Resolve <Authentication>(); _restUrl = "http://tutorscout24.vogel.codes:3000/tutorscout24/api/v1/message/getSentMessages"; var uri = new Uri(string.Format(_restUrl, string.Empty)); var json = JsonConvert.SerializeObject(cmd); var content = new StringContent(json, Encoding.UTF8, "application/json"); HttpResponseMessage response = null; response = await _client.PostAsync(uri, content); if (response.IsSuccessStatusCode) { var msgs = await response.Content.ReadAsStringAsync(); return(JsonConvert.DeserializeObject <List <RestMessage> >(msgs)); } return(null); }