public ActionResult UpdateGovernorator(Governorate_TableMeta Governorate_TableMeta) { using (var client = new HttpClient()) { client.BaseAddress = new Uri("http://localhost:49993/api/Governorate_Table"); //HTTP POST var putTask = client.PutAsJsonAsync <Governorate_TableMeta>("Governorate_Table", Governorate_TableMeta); putTask.Wait(); var result = putTask.Result; if (result.IsSuccessStatusCode) { return(RedirectToAction("Index")); } } return(View(Governorate_TableMeta)); }
public ActionResult CreateGovernorator(Governorate_TableMeta Governorate_TableMeta) { using (var client = new HttpClient()) { client.BaseAddress = new Uri("http://localhost:49993/api/Governorate_Table"); var postTask = client.PostAsJsonAsync <Governorate_TableMeta>("Governorate_TableMeta", Governorate_TableMeta); postTask.Wait(); var result = postTask.Result; if (result.IsSuccessStatusCode) { return(RedirectToAction("Index")); } else { ModelState.AddModelError(string.Empty, "Server Error. Please contact administrator."); } } return(View(Governorate_TableMeta)); }
public ActionResult UpdateGovernorator(int id) { Governorate_TableMeta Governorate_TableMeta = null; using (var client = new HttpClient()) { client.BaseAddress = new Uri("http://localhost:49993/api/Governorate_Table"); //HTTP GET var responseTask = client.GetAsync("Governorate_Table?id=" + id.ToString()); responseTask.Wait(); var result = responseTask.Result; if (result.IsSuccessStatusCode) { var readTask = result.Content.ReadAsAsync <Governorate_TableMeta>(); readTask.Wait(); Governorate_TableMeta = readTask.Result; } } return(View(Governorate_TableMeta)); }