//public async Task<IActionResult> Edit(int id, [Bind("Id,ShipperId,CompanyName,Phone")] Shippers shippers) public async Task <IActionResult> Edit(int shipperId, [FromForm] ShippersForUpdate shipper) { if (shipperId != shipper.ShipperId) { return(NotFound()); } if (ModelState.IsValid) { try { await _serviceShippers.UpdateShipper(shipper); } catch (DbUpdateConcurrencyException) { if (await ShippersExists(shipper.ShipperId) == false) { return(NotFound()); } else { throw; } } //return RedirectToAction(nameof(Index)); return(RedirectToAction("Details", new { shipperId = shipperId })); } return(View(shipper)); }
public async Task UpdateShipper(ShippersForUpdate shipperToUpdate) { var serializedShipperToUpdate = JsonConvert.SerializeObject(shipperToUpdate); var request = new HttpRequestMessage(HttpMethod.Put, $"{apiRoute}/{shipperToUpdate.ShipperId}"); request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue(mediaType)); request.Content = new StringContent(serializedShipperToUpdate); request.Content.Headers.ContentType = new MediaTypeWithQualityHeaderValue(mediaType); var response = await _httpClient.SendAsync(request); response.EnsureSuccessStatusCode(); }