public async Task <IActionResult> UpdateProduct(int id) { UpdateProductcs product = new UpdateProductcs(); using (var httpClient = new HttpClient()) { using (var response = await httpClient.GetAsync("https://localhost:44374/api/Products/GetProduct/" + id)) { string apiResponse = await response.Content.ReadAsStringAsync(); product = JsonConvert.DeserializeObject <UpdateProductcs>(apiResponse); } } return(View(product)); }
public async Task <IActionResult> UpdateProduct([FromForm] UpdateProductcs product) { using (var httpClient = new HttpClient()) { string serailizedProduct = JsonConvert.SerializeObject(product); var inputMessage = new HttpRequestMessage { Content = new StringContent(serailizedProduct, Encoding.UTF8, "application/json") }; inputMessage.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); HttpResponseMessage message = httpClient.PutAsync("https://localhost:44374/api/Products/PutProduct", inputMessage.Content).Result; if (!message.IsSuccessStatusCode) { throw new ArgumentException(message.ToString()); } return(RedirectToAction("Index")); } }