protected void Page_Load(object sender, EventArgs e)
    {
        documentedCandidatesLookup = new Dictionary <int, bool>();
        People documentedCandidates = Election.September2010.GetDocumentedCandidates(Organization.PPSE);

        foreach (Person person in documentedCandidates)
        {
            documentedCandidatesLookup[person.Identity] = true;
        }

        this.RepaterBallots.DataSource = Ballots.ForElection(Election.September2010);
        this.RepaterBallots.DataBind();
    }
Beispiel #2
0
    protected void ButtonCandidateLookup_Click(object sender, EventArgs e)
    {
        Person candidate = this.ComboCandidate.SelectedPerson;

        ViewState[this.ClientID + "SelectedCandidate"] = candidate.Identity;
        Dictionary <int, int> ballotLookup = Ballots.GetBallotsForPerson(candidate);

        this.LabelBallots.Text = string.Empty;

        foreach (int ballotId in ballotLookup.Keys)
        {
            Ballot ballot = Ballot.FromIdentity(ballotId);
            this.LabelBallots.Text += String.Format("{0} (position {1})\r\n", ballot.Name, ballotLookup[ballotId]);
        }

        this.TextPersonalNumber.Text = candidate.PersonalNumber;
        this.TextPhone.Text          = candidate.Phone;
        this.LabelCandidateName.Text = candidate.Canonical;
    }
Beispiel #3
0
    protected void Page_Load(object sender, EventArgs e)
    {
        this.TextCandidates.Style[HtmlTextWriterStyle.Width] = "100%";

        if (_currentUser.Identity != 1 && _currentUser.Identity != 11443 && _currentUser.Identity != 967)
        {
            throw new UnauthorizedAccessException("No access to page");
        }

        if (!Page.IsPostBack)
        {
            Ballots ballots = Ballots.ForElection(Election.September2010);

            foreach (Ballot ballot in ballots)
            {
                this.DropBallots.Items.Add(new ListItem(ballot.Name, ballot.Identity.ToString()));
            }
        }
    }
Beispiel #4
0
 /// <summary>
 /// Searches for sold ballots
 /// </summary>
 /// <returns>All sold ballots</returns>
 public IEnumerable <Ballot> GetSoldBallots()
 {
     return(Ballots.Where(ballot => ballot.SellDate.HasValue).ToList());
 }
Beispiel #5
0
 public void AddBallotToDb(Ballot item)
 {
     Ballots.Add(item);
 }
Beispiel #6
0
        //public ElectionAnalyzerSingleName(Election election, ResultSummary resultSummary, List<Result> results,
        //                                  List<VoteInfo> voteinfos, List<Ballot> ballots, Func<Result, Result> deleteResult,
        //                                  Func<Result, Result> addResult
        //                                  , Func<int> saveChanges, List<Person> people)
        //  : base(election, resultSummary, results, people, ballots, voteinfos, deleteResult, addResult, saveChanges)
        //{
        //}

        public override void AnalyzeEverything()
        {
            PrepareForAnalysis();

            // for single name elections, # votes = # ballots
            ResultSummaryCalc.BallotsReceived
                    = ResultSummaryCalc.NumVoters
                    = ResultSummaryCalc.TotalVotes
                    = VoteInfos.Sum(vi => vi.SingleNameElectionCount).AsInt();

            var invalidBallotGuids =
                Ballots.Where(bi => bi.StatusCode != BallotStatusEnum.Ok).Select(ib => ib.BallotGuid).ToList();

            //VoteInfos.Where(vi => vi.BallotStatusCode != "Ok").Select(ib => ib.BallotGuid).Distinct().ToList();

            ResultSummaryCalc.SpoiledBallots = invalidBallotGuids.Count();

            ResultSummaryCalc.SpoiledVotes =
                VoteInfos.Where(vi => !invalidBallotGuids.Contains(vi.BallotGuid) && vi.VoteStatusCode != VoteStatusCode.Ok).Sum(
                    vi => vi.SingleNameElectionCount).AsInt();

            // vote == ballot for this election
            ResultSummaryCalc.BallotsNeedingReview =
                //Ballots.Count(BallotAnalyzer.BallotNeedsReview);
                VoteInfos.Count(VoteAnalyzer.VoteNeedReview);

            // clear any existing results
            Results.ForEach(InitializeSomeProperties);

            var electionGuid = TargetElection.ElectionGuid;

            _hub.StatusUpdate("Processing votes", true);
            var numDone = 0;

            // collect only valid votes
            foreach (var voteInfo in VoteInfos.Where(vi => vi.VoteStatusCode == VoteStatusCode.Ok))
            {
                numDone++;
//        if (numDone % 10 == 0)
//        {
//          _hub.StatusUpdate("Processed {0} vote{1}".FilledWith(numDone, numDone.Plural()), true);
//        }
//
                // get existing result record for this person, if available
                var result =
                    Results.SingleOrDefault(r => r.ElectionGuid == electionGuid && r.PersonGuid == voteInfo.PersonGuid);
                if (result == null)
                {
                    result = new Result
                    {
                        ElectionGuid = electionGuid,
                        PersonGuid   = voteInfo.PersonGuid.AsGuid()
                    };
                    InitializeSomeProperties(result);
                    Savers.ResultSaver(DbAction.Add, result);
                    Results.Add(result);
                }

                var voteCount = result.VoteCount.AsInt() + voteInfo.SingleNameElectionCount;
                result.VoteCount = voteCount;
            }
            _hub.StatusUpdate("Processed {0} unspoiled vote{1}".FilledWith(numDone, numDone.Plural()));

            FinalizeResultsAndTies();
            FinalizeSummaries();

            var readyForReports = ResultSummaryFinal.UseOnReports.AsBoolean();

            if (UserSession.CurrentElectionStatus == ElectionTallyStatusEnum.Finalized && !readyForReports)
            {
                new ElectionModel().SetTallyStatus(ElectionTallyStatusEnum.Tallying);
            }

            _hub.StatusUpdate("Saving");

            Db.SaveChanges();

            new ResultSummaryCacher(Db).DropThisCache();
            new ResultTieCacher(Db).DropThisCache();
        }
        public override void AnalyzeEverything()
        {
            PrepareForAnalysis();

            ResultSummaryCalc.BallotsNeedingReview = Ballots.Count(BallotAnalyzer.BallotNeedsReview);

            ResultSummaryCalc.TotalVotes = Ballots.Count * TargetElection.NumberToElect;

            var invalidBallotGuids =
                Ballots.Where(b => b.StatusCode != BallotStatusEnum.Ok).Select(b => b.BallotGuid).ToList();

            ResultSummaryCalc.SpoiledBallots = invalidBallotGuids.Count();
            ResultSummaryCalc.SpoiledVotes   =
                VoteInfos.Count(vi => !invalidBallotGuids.Contains(vi.BallotGuid) && vi.VoteStatusCode != VoteHelper.VoteStatusCode.Ok);

            ResultSummaryCalc.BallotsReceived = Ballots.Count - ResultSummaryCalc.SpoiledBallots;

            var electionGuid = TargetElection.ElectionGuid;


            // collect only valid ballots
            _hub.StatusUpdate("Processing ballots", true);
            var numDone       = 0;
            var numVotesTotal = 0;

            foreach (var ballot in Ballots.Where(bi => bi.StatusCode == BallotStatusEnum.Ok))
            {
                numDone++;
                if (numDone % 10 == 0)
                {
                    _hub.StatusUpdate("Processed {0} ballot{1} ({2} votes)".FilledWith(numDone, numDone.Plural(), numVotesTotal), true);
                }

                var ballotGuid = ballot.BallotGuid;
                // collect only valid votes
                foreach (
                    var voteInfoRaw in
                    VoteInfos.Where(vi => vi.BallotGuid == ballotGuid && vi.VoteStatusCode == VoteHelper.VoteStatusCode.Ok))
                {
                    var voteInfo = voteInfoRaw;
                    numVotesTotal++;
                    // get existing result record for this person, if available
                    var result = Results.FirstOrDefault(r => r.ElectionGuid == electionGuid && r.PersonGuid == voteInfo.PersonGuid);
                    //Result result = null;
                    //if (results.Count == 1)
                    //{
                    //  result = results[0];
                    //}
                    //else if (results.Count > 1) {
                    //  // old/bad data!
                    //  foreach (var r in results)
                    //  {
                    //    Savers.ResultSaver(DbAction.AttachAndRemove, r);
                    //    Results.Remove(r);
                    //  }
                    //}
                    if (result == null)
                    {
                        result = new Result
                        {
                            ElectionGuid = electionGuid,
                            PersonGuid   = voteInfo.PersonGuid.AsGuid()
                        };
                        InitializeSomeProperties(result);

                        Savers.ResultSaver(DbAction.Add, result);
                        Results.Add(result);
                    }

                    var voteCount = result.VoteCount.AsInt() + 1;
                    result.VoteCount = voteCount;
                }
            }
            _hub.StatusUpdate("Processed {0} unspoiled ballot{1} ({2} votes)".FilledWith(numDone, numDone.Plural(), numVotesTotal));

            FinalizeResultsAndTies();
            FinalizeSummaries();

            var readyForReports = ResultSummaryFinal.UseOnReports.AsBoolean();

            if (UserSession.CurrentElectionStatus == ElectionTallyStatusEnum.Finalized && !readyForReports)
            {
                new ElectionModel().SetTallyStatus(ElectionTallyStatusEnum.Tallying);
            }

            _hub.StatusUpdate("Saving");

            Db.SaveChanges();

            new ResultSummaryCacher(Db).DropThisCache();
            new ResultTieCacher(Db).DropThisCache();
        }