Exemple #1
0
        public void Confirma()
        {
            if (CandidatoSelecionado.Id != ObjectId.Empty)
            {
                if (CargoIndex == AppViewModel.EleicaoAtual.Cargos.Count())
                {
                    AppViewModel.EleicaoAtual.Votos.Add(new Voto {
                        Candidato = CandidatoSelecionado, Usuario = AppViewModel.Instance.UsuarioAtual
                    });

                    EleicaoDb.Update(AppViewModel.EleicaoAtual);

                    AppViewModel.Finalizado = Visibility.Visible;

                    NumeroCandidato.Clear();
                    CandidatoSelecionado = new Candidato();
                    SoundPlayer player = new System.Media.SoundPlayer(@"Resources\confirma.wav");
                    player.Play();
                }
                else
                {
                    AppViewModel.EleicaoAtual.Votos.Add(new Voto {
                        Candidato = CandidatoSelecionado, Usuario = AppViewModel.Instance.UsuarioAtual
                    });
                    NumeroCandidato.Clear();
                    CandidatoSelecionado = new Candidato();
                    CargoSelecionado     = AppViewModel.EleicaoAtual.Cargos[CargoIndex];
                    CargoIndex++;
                }
            }
        }
Exemple #2
0
        public EleicaoViewModel()
        {
            AppViewModel = AppViewModel.Instance;
            CargoIndex   = 0;

            NumeroCandidato  = new ObservableCollection <string>();
            AddNumberCommand = new DelegateCommand <string>(AddNumber);
            CorrigeCommand   = new DelegateCommand(Corrige);
            ConfirmaCommand  = new DelegateCommand(Confirma);

            EleicaoDb = AppViewModel.Instance.Db.GetCollection <Eleicao>("eleicoes");
            if (EleicaoDb.FindAll().Where(e => e.StatusAtual == Status.Ativa).Count() > 0)
            {
                AppViewModel.EleicaoAtual = EleicaoDb.FindAll().Where(e => e.StatusAtual == Status.Ativa).First();
                CargoSelecionado          = AppViewModel.EleicaoAtual.Cargos[CargoIndex];
                CargoIndex++;
            }
            else
            {
                Show.Window().For(new Alert("Nenhuma eleição ativa encontrada!", "ERRO"));
            }
        }