Esempio n. 1
0
        public IActionResult Post([FromBody] VotacionDTO votacion)
        {
            var voto = _votacion.GuardarVotacion(votacion);

            if (voto.ObjectResult == null)
            {
                return(NotFound());
            }
            else if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            return(Created("", voto));
        }
Esempio n. 2
0
        public PostResult <VotacionDTO> GuardarVotacion(VotacionDTO votacion)
        {
            try
            {
                votacion.FechaDeRespuesta = DateTime.Today;
                var votoDelUsuario = new Votaciones
                {
                    IdGrupo           = votacion.IdGrupo,
                    IdEstablecimiento = votacion.IdEstablecimiento,
                    FechaDeRespuesta  = votacion.FechaDeRespuesta
                };
                var estadoDeLosVotos = context.EstadoDePreferencias.Where(x => x.IdGrupo == votacion.IdGrupo)
                                       .FirstOrDefault();
                var actualizarContadorDeVotos = new EstadoDePreferencias {
                    ContadorDeVotos = ++estadoDeLosVotos.ContadorDeVotos
                };

                context.Votaciones.Add(votoDelUsuario);
                estadoDeLosVotos.ContadorDeVotos = actualizarContadorDeVotos.ContadorDeVotos;

                context.SaveChanges();

                var responseVotacion = new PostResult <VotacionDTO>
                {
                    ObjectResult = votacion,
                };

                return(responseVotacion);
            }
            catch (Exception ex)
            {
                var responseVotacion = new PostResult <VotacionDTO>
                {
                    MensajePersonalizado = ex.Message,
                };
                return(responseVotacion);
            }
        }