private void Vote_OnClick(object sender, RoutedEventArgs e) { var vote = new Vote(); var confirmVote = MessageBox.Show("Please confirm your vote.", "VOTE", MessageBoxButton.YesNo, MessageBoxImage.Question); if (confirmVote == MessageBoxResult.No) { return; } var block = new BlockedJsonData().GetAll(); if (block == null) { ErrorMessage.ShowError("Error blocked pesel data."); return; } if (block.Contains(_voter.Pesel)) { vote.ValidVote = false; vote.WithoutRight = true; MessageBox.Show("You do not have the right to vote. Your vote will not be valid.", "Warning", MessageBoxButton.OK); } if (_voteViewModel.Candidates.Count(x => x.Vote) != 1) { vote.ValidVote = false; } else { vote.Candidate = _voteViewModel.Candidates.SingleOrDefault(x => x.Vote); } vote.Voters = _voter; var votersRepository = new VotersRepository(); if (votersRepository.IsExist(_voter)) { MessageBox.Show("You can't vote. You have already cast your vote.", "Warning", MessageBoxButton.OK); return; } votersRepository.Save(_voter); var voteRepository = new VoteRepository(); voteRepository.Save(vote); new StatisticWindow().Show(); Close(); }
public VotersController(VotersRepository votersRepository) { this._votersRepository = votersRepository; }
public VotersController(VotersRepository voters, ApplicationDbContext context) { _voters = voters; _ctx = context; }