示例#1
0
        public IActionResult FanalizarEtapa(int idEtapa)
        {
            var etapaParticipanteDao = new EtapaParticipanteDao(_context);

            if (!etapaParticipanteDao.ValidarParticipanteNota(idEtapa))
            {
                return(NotFound("Alguns participantes não tem nota ainda"));
            }
            else if (etapaParticipanteDao.EtapaFinalizada(idEtapa))
            {
                return(NotFound("Essa etapa já foi finalizada"));
            }

            var Vencedores = etapaParticipanteDao.Vencedores(idEtapa);
            var Perdedores = etapaParticipanteDao.Perdedores(idEtapa);

            for (int i = 0; i < Vencedores.Count(); i++)
            {
                Devedores d = new Devedores();
                d.fk_participante_ganhardor = Vencedores.ElementAt(i).fk_participante;
                d.fk_participante_perdedor  = Perdedores.ElementAt(i).fk_participante;
                d.fk_etapa_devedores        = idEtapa;
                _context.Devedores.Add(d);
                _context.SaveChanges();
            }
            return(Ok());
        }
示例#2
0
        public IActionResult Post(
            [FromBody] EtapaParticipante etapaParticipante)
        {
            if (etapaParticipante.fk_participante.ToString() == null)
            {
                return(NotFound());
            }

            var  etapa         = new EtapaParticipanteDao(_context);
            bool notaExistente = etapa.validarNotaExistente(etapaParticipante.fk_etapa, etapaParticipante.fk_participante, DateTime.Now.Year);

            if (notaExistente)
            {
                return(NotFound("A nota desse participante já foi preenchida!"));
            }

            EtapaParticipante e = new EtapaParticipante();

            e.fk_etapa        = etapaParticipante.fk_etapa;
            e.fk_participante = etapaParticipante.fk_participante;
            e.nota            = etapaParticipante.nota;
            e.ano             = DateTime.Now.Year;
            _context.EtapaParticipantes.Add(e);
            _context.SaveChanges();
            return(NoContent());
        }