//Carregará a View após pegar todos os dados da Arma public async Task <ActionResult> EditAsync(int id) { HttpClient httpClient = new HttpClient(); HttpResponseMessage response = await httpClient.GetAsync(uriBaseArma + id.ToString()); string serialized = await response.Content.ReadAsStringAsync(); ArmaViewModel a = await Task.Run(() => JsonConvert.DeserializeObject <ArmaViewModel>(serialized)); return(View(a)); }
public async Task <ActionResult> EditAsync(ArmaViewModel a) { HttpClient httpClient = new HttpClient(); var content = new StringContent(JsonConvert.SerializeObject(a)); content.Headers.ContentType = new MediaTypeHeaderValue("application/json"); HttpResponseMessage response = await httpClient.PutAsync(uriBaseArma, content); TempData["Mensagem"] = string.Format("Arma {0} atualizada com sucesso!", a.Nome); return(RedirectToAction("Index")); }
public async Task <ActionResult> CreateAsync(ArmaViewModel a) { HttpClient httpClient = new HttpClient(); var content = new StringContent(JsonConvert.SerializeObject(a)); content.Headers.ContentType = new MediaTypeHeaderValue("application/json"); HttpResponseMessage response = await httpClient.PostAsync(uriBaseArma, content); string serialized = await response.Content.ReadAsStringAsync(); await Task.Run(() => JsonConvert.DeserializeObject <List <ArmaViewModel> >(serialized)); TempData["Mensagem"] = string.Format("Arma {0} salva com sucesso!", a.Nome); return(RedirectToAction("Index")); }