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); } } }
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; } }
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()); }