Exemplo n.º 1
0
        public Voto RegistrarVoto(Associado eleitor, Elegivel candidato, string ip)
        {
            ValidarPeriodoRealizadoParaVotacao();
            var voto = new Voto(this, eleitor, candidato, ip);

            _votos.Add(voto);
            candidato.RegistrarVoto();
            return(voto);
        }
Exemplo n.º 2
0
        }                 // EF

        public Voto(Votacao votacao, Associado associado, Elegivel candidato, string ip) : base()
        {
            Votacao     = votacao ?? throw new CustomException("É preciso informar a qual votação se refere esse voto.");
            VotacaoId   = votacao.Id;
            Eleitor     = associado ?? throw new CustomException("É preciso informar o associado que está votando.");
            EleitorId   = associado.Id;
            Candidato   = candidato ?? throw new CustomException("É preciso informar o associado que está votando.");
            CandidatoId = candidato.Id;
            Horario     = DateTime.Now;
            Ip          = ip;
        }
Exemplo n.º 3
0
        public virtual Elegivel RemoverElegivel(Elegivel elegivel)
        {
            if (PeriodoRealizado.DataFim.HasValue)
            {
                throw new CustomException("Não é possível remover elegíveis após o término da votação.");
            }

            if (!Elegiveis.Contains(elegivel))
            {
                throw new CustomException("Elegível não cadastrado.");
            }

            var elegivelRemovido = Elegiveis.Single(e => e.Equals(elegivel));

            _elegiveis.Remove(elegivelRemovido);
            return(elegivelRemovido);
        }
Exemplo n.º 4
0
        public virtual Elegivel AdicionarElegivel(Associado associado)
        {
            if (PeriodoRealizado.DataFim.HasValue)
            {
                throw new CustomException("Não é possível adicionar elegíveis após o término da votação.");
            }

            if (!Ciclo.Associados.Contains(associado))
            {
                throw new CustomException("Associado não cadastrado nesse ciclo.");
            }

            if (Elegiveis.Any(e => e.Associado.Equals(associado)))
            {
                throw new CustomException("Esse associado já está na lista de elegíveis para essa votação.");
            }

            var elegivel = new Elegivel(associado, this);

            _elegiveis.Add(elegivel);
            return(elegivel);
        }