Exemple #1
0
        /// <Summary>Update the Ballot status of this ballot, based on these Votes.</Summary>
        /// <param name="ballot">The Ballot or vBallotInfo to check and update.</param>
        /// <param name="currentVotes">The list of Votes in this Ballot</param>
        /// <param name="refreshVoteStatus"></param>
        /// <returns>Returns the updated status code</returns>
        public BallotStatusWithSpoilCount UpdateBallotStatus(Ballot ballot, List <VoteInfo> currentVotes,
                                                             bool refreshVoteStatus, bool forceSave = false)
        {
            //double check:
            currentVotes.ForEach(vi => AssertAtRuntime.That(vi.BallotGuid == ballot.BallotGuid));

            if (refreshVoteStatus)
            {
                VoteAnalyzer.UpdateAllStatuses(currentVotes, new VoteCacher(Db).AllForThisElection, new Savers(Db).VoteSaver);
            }

            if (DetermineStatusFromVotesList(ballot.StatusCode, currentVotes, out var newStatus, out var spoiledCount) ||
                forceSave)
            {
                BallotSaver(DbAction.Attach, ballot);
                ballot.StatusCode = newStatus;
                //                BallotSaver(DbAction.Save, ballot);

                new BallotCacher(Db).UpdateItemAndSaveCache(ballot);
                Db.SaveChanges();
            }

            Db.SaveChanges();

            return(new BallotStatusWithSpoilCount
            {
                Status = BallotStatusEnum.Parse(newStatus),
                SpoiledCount = spoiledCount
            });
        }
Exemple #2
0
        /// <Summary>Update the Ballot status of this ballot, based on these Votes.</Summary>
        /// <param name="ballot">The Ballot or vBallotInfo to check and update.</param>
        /// <param name="currentVotes">The list of Votes in this Ballot</param>
        /// <param name="refreshVoteStatus"></param>
        /// <returns>Returns the updated status code</returns>
        public BallotStatusWithSpoilCount UpdateBallotStatus(Ballot ballot, List <VoteInfo> currentVotes, bool refreshVoteStatus)
        {
            //double check:
            currentVotes.ForEach(vi => AssertAtRuntime.That(vi.BallotGuid == ballot.BallotGuid));

            if (refreshVoteStatus)
            {
                VoteAnalyzer.UpdateAllStatuses(currentVotes, new VoteCacher(Db).AllForThisElection, new Savers(Db).VoteSaver);
            }

            string newStatus;
            int    spoiledCount;


            //if (IsSingleNameElection)
            //{
            //  if (ballot.StatusCode != BallotStatusEnum.Ok)
            //  {
            //    BallotSaver(DbAction.Attach, ballot);

            //    ballot.StatusCode = BallotStatusEnum.Ok;

            //    BallotSaver(DbAction.Save, ballot);
            //  }
            //  return new BallotStatusWithSpoilCount
            //    {
            //      Status = BallotStatusEnum.Ok,
            //      SpoiledCount = 0
            //    };
            //}


            if (DetermineStatusFromVotesList(ballot.StatusCode, currentVotes, out newStatus, out spoiledCount))
            {
                BallotSaver(DbAction.Attach, ballot);
                ballot.StatusCode = newStatus;
                BallotSaver(DbAction.Save, ballot);
            }
            return(new BallotStatusWithSpoilCount
            {
                Status = BallotStatusEnum.Parse(newStatus),
                SpoiledCount = spoiledCount
            });
        }
Exemple #3
0
        public void RefreshBallotStatuses()
        {
            new BallotCacher(Db).DropThisCache();
            new VoteCacher(Db).DropThisCache();

            // first refresh person vote statuses
            new PeopleModel().EnsureFlagsAreRight(People, _hub, Savers.PersonSaver);

            // then refresh all votes
            _hub.StatusUpdate("Reviewing votes");
            VoteAnalyzer.UpdateAllStatuses(VoteInfos, Votes, Savers.VoteSaver);

            // then refresh all ballots
            _hub.StatusUpdate("Reviewing ballots");
            var ballotAnalyzer = new BallotAnalyzer(TargetElection, Savers.BallotSaver);

            ballotAnalyzer.UpdateAllBallotStatuses(Ballots, VoteInfos);

            Db.SaveChanges();
        }