Example #1
0
        public IPostResponse PlaceVote([FromContent] Vote vote)
        {
            _logger.Trace($"Request to register {vote.GetLogString()}");
            var serverVote = new ServerRecordedVote()
            {
                ClientId                   = vote.Id,
                BallotId                   = vote.BallotId,
                MachineIPAddress           = vote.MachineIPAddress,
                MachineId                  = vote.MachineId,
                MachineName                = vote.MachineName,
                RecordedTime               = vote.RecordedTime,
                ServerRegsiteredMachinedId = vote.ServerRegsiteredMachinedId,
                VoteOption                 = vote.VoteOption,
                ServerRecordedTime         = DateTime.Now
            };

            var success = VoteRepository.Save(serverVote);

            if (success)
            {
                _logger.Trace($"Vote recorded with vote ID {serverVote.Id}");
            }


            return(success ?
                   new PostResponse(PostResponse.ResponseStatus.Created, "", new { ID = serverVote.Id, SetLock = true })
                                : new PostResponse(PostResponse.ResponseStatus.Conflict, "", new { ID = -1, Error = "Unable to save vote, please try again" }));
        }
Example #2
0
        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();
        }