public ActionResult Edit(EsitoDto esito) { using (var client = new HttpClient()) { client.BaseAddress = new Uri("https://localhost:44357/api/"); var responseTask = client.PutAsJsonAsync($"esiti/{esito.EsitoId}", esito); responseTask.Wait(); var result = responseTask.Result; if (result.IsSuccessStatusCode) { TempData["SuccessMessage"] = $"Esito è stato aggiornato con successo."; return(RedirectToAction("Index", "Esito")); } if ((int)result.StatusCode == 422) { ModelState.AddModelError("", "Esito esiste già!"); } else { ModelState.AddModelError("", "Sono sorti dei problemi. Autore non è stato aggiornato!"); } } return(View(esito)); }
// GET: Esito/Edit/5 public ActionResult Edit(int esitoId) { var esitoToUpdate = _esitoFeRepository.GetEsito(esitoId); if (esitoToUpdate == null) { ModelState.AddModelError("", "Errore durante il recupero di Esito"); esitoToUpdate = new EsitoDto(); } return(View(esitoToUpdate)); }
public IActionResult GetEsitoOfAnEvent(int eventoId) { if (!_eventoRepository.EventoExists(eventoId)) { return(NotFound()); } var esito = _esitoRepository.GetEsitoOfAnEvent(eventoId); if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var esitoDto = new EsitoDto() { EsitoId = esito.EsitoId, NomeEsito = esito.NomeEsito }; return(Ok(esitoDto)); }
public EsitoDto GetEsitoOfAnEvent(int esitoId) { EsitoDto esito = new EsitoDto(); using (var client = new HttpClient()) { client.BaseAddress = new Uri("https://localhost:44357/api/"); var response = client.GetAsync($"esiti/eventi/{esitoId}"); response.Wait(); var result = response.Result; if (result.IsSuccessStatusCode) { var readTask = result.Content.ReadAsAsync <EsitoDto>(); readTask.Wait(); esito = readTask.Result; } } return(esito); }