public async Task <string> InsertComment(KomentariModel model) { string res = string.Empty; Uri path = new Uri($"http://10.0.2.2:58830/api/Comments?Komentar={model.Komentar}&KorisnikID={model.KorisnikID}&autoID={model.AutomobilID}"); HttpRequestMessage httpRequest = new HttpRequestMessage { RequestUri = path, Method = HttpMethod.Post }; httpRequest.Headers.Add("Accept", "application/json"); httpRequest.Headers.Add("Host", "localhost"); HttpResponseMessage httpResponse = new HttpResponseMessage(); try { httpResponse = client.SendAsync(httpRequest).Result; if (httpResponse.StatusCode == System.Net.HttpStatusCode.OK || httpResponse.StatusCode == System.Net.HttpStatusCode.NoContent) { res = "OK"; } } catch { res = "failed"; } return(res); }
protected async void InsertComment() { Settings.UserID = 1; if (Settings.UserID == 0) { return; } KomentariModel model = new KomentariModel(); model.KorisnikID = Settings.UserID; model.AutomobilID = automobiliModel.AutomobilID; model.Komentar = WrittenComment; string response = await apiHelper.InsertComment(model); if (response == "OK") { Komentari.Add(model); } }