public ActionResult Edit(FazioneDto fazioneModel) { using (var client = new HttpClient()) { client.BaseAddress = new Uri("https://localhost:44357/api/"); var responseTask = client.PutAsJsonAsync($"fazioni/{fazioneModel.FazioneId}", fazioneModel); responseTask.Wait(); var result = responseTask.Result; if (result.IsSuccessStatusCode) { TempData["SuccessMessage"] = $"Fazione è stato aggiornato con successo."; return(RedirectToAction("Index", "Fazione")); } if ((int)result.StatusCode == 422) { ModelState.AddModelError("", "Fazione Esiste già!"); } else { ModelState.AddModelError("", "Qualche tipo di errore. Fazione non aggiornato!"); } } return(View(fazioneModel)); }
// GET: Fazione/Edit/5 public ActionResult Edit(int fazioneId) { var fazioneToUpdate = _fazioneFeRepository.GetFazione(fazioneId); if (fazioneToUpdate == null) { ModelState.AddModelError("", "Errore durante l'ottenimento della Fazione"); fazioneToUpdate = new FazioneDto(); } return(View(fazioneToUpdate)); }
public IActionResult GetFazioneOfAMandante(int mandanteId) { if (!_mandanteRepository.MandanteExists(mandanteId)) { return(NotFound()); } var fazione = _mandanteRepository.GetFazioneOfAMandante(mandanteId); if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var fazioneDto = new FazioneDto() { FazioneId = fazione.FazioneId, NomeFazione = fazione.NomeFazione }; return(Ok(fazioneDto)); }
public IActionResult GetFazioneByAuthor(int autoreId) { if (!_autoreRepository.AutoreExists(autoreId)) { return(NotFound()); } var fazione = _fazioneRepository.GetFazioneByAuthor(autoreId); if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var fazioneDto = new FazioneDto() { FazioneId = fazione.FazioneId, NomeFazione = fazione.NomeFazione }; return(Ok(fazioneDto)); }
public FazioneDto GetFazioneOfAMandante(int mandanteId) { FazioneDto fazione = new FazioneDto(); using (var client = new HttpClient()) { client.BaseAddress = new Uri("https://localhost:44357/api/"); var response = client.GetAsync($"mandanti/{mandanteId}/fazione"); response.Wait(); var result = response.Result; if (result.IsSuccessStatusCode) { var readTask = result.Content.ReadAsAsync <FazioneDto>(); readTask.Wait(); fazione = readTask.Result; } } return(fazione); }