Exemplo n.º 1
0
        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));
        }
Exemplo n.º 2
0
        // 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));
        }
Exemplo n.º 3
0
        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));
        }
Exemplo n.º 4
0
        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);
        }