Beispiel #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
            });
        }
Beispiel #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
            });
        }