public IActionResult New(WebApplication1.Models.Task task) { using (var client = new HttpClient()) { //HTTP PUT var postTask = client.PostAsync("https://localhost:44396/api/taskInsert", new StringContent(JsonConvert.SerializeObject(task), Encoding.UTF8, "application/json")); postTask.Wait(); var result = postTask.Result; if (result.IsSuccessStatusCode) { return(RedirectToAction("Index")); } } return(View("New")); }
public ActionResult Edit(int id) { WebApplication1.Models.Task task = null; using (var client = new HttpClient()) { //HTTP GET var getTask = client.GetAsync("https://localhost:44396/api/task/" + id.ToString()); getTask.Wait(); var result = getTask.Result; if (result.IsSuccessStatusCode) { var readTask = result.Content.ReadAsStringAsync(); readTask.Wait(); task = JsonConvert.DeserializeObject <Task>(readTask.Result); } } return(View("Edit", task)); }