예제 #1
0
 public MainWindow()
 {
     using (var _context = new ClientVotacaoContext())
     {
         int user = int.Parse(Environment.UserName);
         //int user = 0912831923;
         bool vote = false;
         try
         {
             vote = _context.Vote.Where(v => v.CPF == user && v.Moment.Year == DateTime.Now.Year).Any();
             var election = _context.Election.Where(e => e.Year == DateTime.Now.Year).FirstOrDefault();
             if (election != null && election.HasStarted && !election.HasFinished && !vote)
             {
                 InitializeComponent();
                 MainFrame.Navigate(new Intro());
             }
             else
             {
                 Application.Current.Shutdown();
             }
         }
         catch (Exception ex)
         {
             MessageBox.Show(ex.Message);
         }
     }
 }
예제 #2
0
 public Candidates()
 {
     InitializeComponent();
     using (var _context = new ClientVotacaoContext())
     {
         Election                   = _context.Election.Where(e => e.Year == DateTime.Now.Year).FirstOrDefault();
         this.CandidateList         = _context.Candidate.Where(c => c.Election.Year == DateTime.Now.Year).ToList();
         CandidatesList.ItemsSource = this.CandidateList;
     }
 }
예제 #3
0
 private void ConfirmButton_Click(object sender, RoutedEventArgs e)
 {
     using (var _context = new ClientVotacaoContext())
     {
         Vote vote = new Vote()
         {
             CandidateID = Candidate.Id,
             CPF         = int.Parse(Environment.UserName),
             Moment      = DateTime.Now
         };
         _context.Vote.Add(vote);
         try
         {
             _context.SaveChanges();
         }
         catch (Exception ex)
         {
             MessageBox.Show(ex.Message);
         }
     }
     NavigationService.Navigate(new Final());
 }