public ActionResult Edit(VeterinarioViewModel veterinario) { using (var client = new HttpClient()) { client.BaseAddress = new Uri("http://localhost:49770/api/Veterinario"); //HTTP POST var putTask = client.PutAsJsonAsync <VeterinarioViewModel>("Veterinario", veterinario); putTask.Wait(); var result = putTask.Result; if (result.IsSuccessStatusCode) { return(RedirectToAction("Index")); } } return(View(veterinario)); }
public ActionResult Create(VeterinarioViewModel veterinario) { using (var client = new HttpClient()) { client.BaseAddress = new Uri("http://localhost:49770/api/Veterinario"); //HTTP POST var postTask = client.PostAsJsonAsync <VeterinarioViewModel>("Veterinario", veterinario); postTask.Wait(); var result = postTask.Result; if (result.IsSuccessStatusCode) { return(RedirectToAction("Index")); } } ModelState.AddModelError(string.Empty, "Server Error. contacta con el administrador"); return(View(veterinario)); }
public ActionResult Edit(int id) { VeterinarioViewModel veterinario = null; using (var client = new HttpClient()) { client.BaseAddress = new Uri("http://localhost:49770/api/"); //HTTP Get var responseTask = client.GetAsync("Veterinario?id=" + id); responseTask.Wait(); var result = responseTask.Result; if (result.IsSuccessStatusCode) { var readTask = result.Content.ReadAsAsync <VeterinarioViewModel>(); readTask.Wait(); veterinario = readTask.Result; } } return(View(veterinario)); }