public async Task <ActionResult> Create(FeedBack feed) { HttpClient client = new HttpClient(); client.BaseAddress = new Uri("http://localhost:8080/"); client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); var response = await client.PostAsJsonAsync("add-Feed/" + feed.jdf_id, feed); if (response.IsSuccessStatusCode) { return(RedirectToAction("Index")); } HttpResponseMessage httpResponseMessage = client.GetAsync("/getjdf").Result; IEnumerable <Jdf> jdfs; if (httpResponseMessage.IsSuccessStatusCode) { jdfs = httpResponseMessage.Content.ReadAsAsync <IEnumerable <Jdf> >().Result; } else { jdfs = null; } ViewBag.jdf_id = new SelectList(jdfs, "jdf"); return(View(feed)); }
public ActionResult Edit(int id, float note, FeedBack fed) { using (var client = new HttpClient()) { client.BaseAddress = new Uri("http://localhost:8080"); //HTTP POST var putTask = client.PutAsJsonAsync <FeedBack>("/mettreAjourNoteByFeedId/" + note + "/" + id, fed); putTask.Wait(); var result = putTask.Result; if (result.IsSuccessStatusCode) { return(RedirectToAction("Index")); } } return(View(fed)); }
public ActionResult Edit(int id) { FeedBack fed = null; using (var client = new HttpClient()) { client.BaseAddress = new Uri("http://localhost:8080"); //HTTP GET var responseTask = client.GetAsync("/getFeed/" + id); // responseTask.Wait(); var result = responseTask.Result; if (result.IsSuccessStatusCode) { var readTask = result.Content.ReadAsAsync <FeedBack>(); readTask.Wait(); fed = readTask.Result; } } return(View(fed)); }