public async Task <EditarAmigoViewModel> PutAsync(Guid id, EditarAmigoViewModel editarAmigoViewModel) { var editarAmigoViewModelJson = JsonConvert.SerializeObject(editarAmigoViewModel); var conteudo = new StringContent(editarAmigoViewModelJson, Encoding.UTF8, "application/json"); var response = await _httpClient.PutAsync("api/amigos/" + id, conteudo); if (response.IsSuccessStatusCode) { return(editarAmigoViewModel); } else if (response.StatusCode == HttpStatusCode.UnprocessableEntity) { var responseContent = await response.Content.ReadAsStringAsync(); var listErro = JsonConvert.DeserializeObject <List <string> >(responseContent); editarAmigoViewModel.Errors = listErro; return(editarAmigoViewModel); } return(editarAmigoViewModel); }
public async Task <ActionResult> Edit(Guid id, EditarAmigoViewModel editarAmigoViewModel) { var urlFoto = UploadFotoAmigo(editarAmigoViewModel.Foto); editarAmigoViewModel.UrlFoto = urlFoto.Result; await _amigoApi.PutAsync(id, editarAmigoViewModel); try { return(RedirectToAction(nameof(Index))); } catch { return(View()); } }