Esempio n. 1
0
        public void GetSingleVoteElectionResults()
        {
            var _context = new VotingContext();
            var _manager = new VotingManager();

            var canidates = _manager.GetVoteResults();



            var electionResultsForSingleVoteItems = new Dictionary <SingleVoteItem, Dictionary <bool, int> >();

            var singleVoteItems = canidates.Where(x => x.SingleVoteId != null).ToList();

            foreach (var singleVoteItem in singleVoteItems)
            {
                if (singleVoteItem.SingleVoteItem != null &&
                    electionResultsForSingleVoteItems.ContainsKey(singleVoteItem.SingleVoteItem))
                {
                    if (singleVoteItem.VotedYes != null && singleVoteItem.VotedYes.Value)
                    {
                        electionResultsForSingleVoteItems[singleVoteItem.SingleVoteItem][true]++;
                    }
                    if (singleVoteItem.VotedNo != null && singleVoteItem.VotedNo.Value)
                    {
                        electionResultsForSingleVoteItems[singleVoteItem.SingleVoteItem][false]++;
                    }
                }
                else
                {
                    var firstEntry = new Dictionary <bool, int>();
                    firstEntry.Add(true, 0);
                    firstEntry.Add(false, 0);
                    if (singleVoteItem.VotedYes != null && singleVoteItem.VotedYes.Value)
                    {
                        firstEntry[true]++;
                    }
                    if (singleVoteItem.VotedNo != null && singleVoteItem.VotedNo.Value)
                    {
                        firstEntry[false]++;
                    }
                    if (singleVoteItem.SingleVoteItem != null)
                    {
                        electionResultsForSingleVoteItems.Add(singleVoteItem.SingleVoteItem, firstEntry);
                    }
                }
            }


            var test = electionResultsForSingleVoteItems;
        }
Esempio n. 2
0
        public void GetElectionResults()
        {
            var _context = new VotingContext();
            var _manager = new VotingManager();

            var canidates = _manager.GetVoteResults();



            var electionResultsForPresidents = new Dictionary <RankingVoteItem, Dictionary <int, int> >();

            var presidentialCandidates = canidates.Where(x => x.RankingVoteId != null).ToList();

            foreach (var presidentialCandidate in presidentialCandidates)
            {
                if (presidentialCandidate.RankingVoteId != null &&
                    electionResultsForPresidents.ContainsKey(presidentialCandidate.RankingVoteItem))
                {
                    if (electionResultsForPresidents[presidentialCandidate.RankingVoteItem]
                        .ContainsKey(presidentialCandidate.RankingVoteItem.Ranking))
                    {
                        var i = electionResultsForPresidents[presidentialCandidate.RankingVoteItem][
                            (int)presidentialCandidate.Ranking];
                        electionResultsForPresidents[presidentialCandidate.RankingVoteItem][
                            (int)presidentialCandidate.Ranking] = i++;
                        electionResultsForPresidents[presidentialCandidate.RankingVoteItem] = electionResultsForPresidents[presidentialCandidate.RankingVoteItem].OrderBy(x => x.Key).ToDictionary(x => x.Key, x => x.Value);
                    }
                    else
                    {
                        electionResultsForPresidents[presidentialCandidate.RankingVoteItem].Add((int)presidentialCandidate.Ranking, 1);
                        electionResultsForPresidents[presidentialCandidate.RankingVoteItem] = electionResultsForPresidents[presidentialCandidate.RankingVoteItem].OrderBy(x => x.Key).ToDictionary(x => x.Key, x => x.Value);
                    }
                }
                else
                {
                    if (presidentialCandidate.RankingVoteId != null)
                    {
                        var firstEntry = new Dictionary <int, int>();
                        firstEntry.Add((int)presidentialCandidate.Ranking, 1);
                        electionResultsForPresidents.Add(presidentialCandidate.RankingVoteItem, firstEntry);
                        electionResultsForPresidents[presidentialCandidate.RankingVoteItem] = electionResultsForPresidents[presidentialCandidate.RankingVoteItem].OrderBy(x => x.Key).ToDictionary(x => x.Key, x => x.Value);
                    }
                }
            }


            var test = electionResultsForPresidents;
        }
Esempio n. 3
0
        public ActionResult Index()
        {
            if (!User.IsInRole(RoleName.CanSeeElectionResults))
            {
                return(RedirectToAction("Index", "Home"));
            }
            Log.Info("Admin Viewing Results");
            var manager   = new VotingManager();
            var viewModel = new ElectionResultsViewModel();

            var results = manager.GetVoteResults();

            viewModel.PresidentResults = manager.RankedVotingManager.GetRankingResults(results);
            viewModel.GetNumberOfRankings();
            var singleVoteItems = manager.SingleVoteManager.GetSingleVoteResults(results);

            viewModel.SupremeCourtResult = singleVoteItems.Where(x => x.Key.CandidateItem != null).ToDictionary(x => x.Key, x => x.Value);
            viewModel.BallotIssue        = singleVoteItems.Where(x => x.Key.Issue != null).ToDictionary(x => x.Key, x => x.Value);
            viewModel.StateReps          = manager.MultiVoteManager.GetMultiVoteResults(results);
            return(View(viewModel));
        }