コード例 #1
0
        public async Task <ActionResult <IEnumerable <Race> > > Get()
        {
            var step1 = _context.Steps.Where(step => step.StepNumber == STEP_NUMBER).First();

            VotingPage votingPage = new VotingPage()
            {
                PageTitle       = step1.StepTitle,
                PageDescription = step1.StepDescription,
                PageNumber      = STEP_NUMBER,
            };

            var races = await _context.Races
                        .Where(race => race.ElectionId == _runningElection)
                        .Select(race => new
            {
                race.BallotOrder,
                race.PositionName,
                race.NumberNeeded,
                race.Description,
                Candidates = race.CandidateRaces.Select(cr => new
                {
                    cr.BallotOrder,
                    cr.Candidate.CandidateId,
                    cr.Candidate.Name,
                    cr.Candidate.Picture,
                    OrganizationName = cr.Candidate.Organization.Name,
                    Details          = cr.Candidate.Details.Select(detail => new
                    {
                        detail.Title,
                        detail.Text,
                        detail.Format,
                    }),
                    Contacts = cr.Candidate.Contacts.Select(contact => new
                    {
                        contact.ContactMethod,
                        contact.ContactValue,
                    }),
                })
            })
                        .ToListAsync();

            return(Ok(new
            {
                votingPage,
                races,
            }));
        }
コード例 #2
0
        public async Task <ActionResult <IEnumerable <PollingPlace> > > GetPollingPlaces()
        {
            var step3 = _context.Steps.Where(step => step.StepNumber == STEP_NUMBER).First();

            VotingPage votingPage = new VotingPage()
            {
                PageTitle       = step3.StepTitle,
                PageDescription = step3.StepDescription,
                PageNumber      = STEP_NUMBER,
            };

            var pollingPlaces = await _context.PollingPlaces
                                .Where(pp => pp.ElectionId == _runningElectionID)
                                .Select(pp => new
            {
                pp.PollingPlaceId,
                pp.PollingPlaceName,
                pp.Address,
                pp.PollingStationName,
                pp.ParkingInfo,
                pp.WheelchairInfo,
                pp.AdvanceOnly,
                pp.LocalArea,
                pp.Phone,
                pp.Email,
                pp.Latitude,
                pp.Longitude,
                PollingPlaceDates = pp.PollingPlaceDates.Select(ppd => new
                {
                    ppd.PollingDate,
                    ppd.StartTime,
                    ppd.EndTime,
                })
            })
                                .ToListAsync();

            return(Ok(new
            {
                votingPage,
                pollingPlaces
            }));
        }
コード例 #3
0
        public async Task <ActionResult <IEnumerable <BallotIssue> > > Get()
        {
            var step2 = _context.Steps.Where(step => step.StepNumber == STEP_NUMBER).First();

            VotingPage votingPage = new VotingPage()
            {
                PageTitle       = step2.StepTitle,
                PageDescription = step2.StepDescription,
                PageNumber      = STEP_NUMBER,
            };

            var ballotIssues = await _context.BallotIssues
                               .Include(b => b.BallotIssueOptions)
                               .Where(b => b.ElectionId == _runningElectionID)
                               .ToListAsync();

            return(Ok(new
            {
                votingPage,
                ballotIssues
            }));
        }
コード例 #4
0
        //Logs user with provided first name, last name and personal id number
        private void btnLogin_Click(object sender, RoutedEventArgs e)
        {
            //Connect to database and create Voter object
            VotingDatabaseEntities db = new VotingDatabaseEntities();
            string personalIdNumber   = tbPersonalId.Text;
            Voter  loggedVoter        = new Voter(tbFirstName.Text, tbLastName.Text, personalIdNumber);

            //Failure flags
            bool isBlacklisted = false;
            bool isUnderaged   = false;
            bool hasVoted      = false;
            bool isIncorrect   = false;


            //Check validity of personal id number
            isIncorrect   = PESELValidator.PESEL(personalIdNumber);
            isBlacklisted = PESELValidator.IsBlacklisted(personalIdNumber);
            isUnderaged   = PESELValidator.IsUnderaged(personalIdNumber);

            var voters = db.Voters;
            var result = voters.Select(x => x.PersonalIdNumber).ToList();

            //Decrypt personal id number from database and compare it with given one
            if (result.Count != 0)
            {
                foreach (string voterId in result)
                {
                    if (Encrypter.DecryptString(voterId) == personalIdNumber)
                    {
                        hasVoted = true;
                        break;
                    }
                }
            }



            //Handling of invalid personal id number
            if (isIncorrect)
            {
                MessageBox.Show("Personal ID number is incorrect!");
            }
            else if (isUnderaged || isBlacklisted)
            {
                //Update information about disallowed logging tries
                var statisticsTable = db.Statistics;
                var disallowedTries = statisticsTable.SingleOrDefault(x => x.StatisticId == 1);
                disallowedTries.DisallowedTries++;
                db.SaveChanges();
                MessageBox.Show("You are disallowed to vote!");
            }
            else if (hasVoted)
            {
                MessageBox.Show("You have already voted!");
            }
            else
            {
                //If personal id number is valid, sendu user to voting page
                VotingPage votingPage = new VotingPage(loggedVoter);
                NavigationService.Navigate(votingPage);
            }
        }