public ActionResult UpdatePrice(int id, FishDefinitionViewModel model) { var priceContent = new StringContent(JsonConvert.SerializeObject(model.Price), System.Text.Encoding.UTF8, "application/json"); var client = GetHttpClient(); var msg = client.PutAsync($"{baseAddr}/price/{id}", priceContent).Result; //msg.EnsureSuccessStatusCode(); if (!msg.IsSuccessStatusCode) { switch (msg.StatusCode) { case HttpStatusCode.NotFound: ModelState.AddModelError("Price", "Price must be changed"); return(View(model)); } } return(RedirectToAction(nameof(Index))); }
public ActionResult Edit(int id, FishDefinitionViewModel model) { try { HttpClient client = GetHttpClient(); var myContent = JsonConvert.SerializeObject(model); var buffer = System.Text.Encoding.UTF8.GetBytes(myContent); using (var byteContent = new ByteArrayContent(buffer)) { byteContent.Headers.ContentType = new MediaTypeHeaderValue("application/json"); var result = client.PutAsync($"{baseAddr}/update/{id}", byteContent).Result; result.EnsureSuccessStatusCode(); } return(RedirectToAction(nameof(Index))); } catch { return(View()); } }