public VoteInfo(Vote vote, Election election, Ballot ballot, Location location, Person person) { VoteId = vote.C_RowId; SingleNameElectionCount = vote.SingleNameElectionCount; PositionOnBallot = vote.PositionOnBallot; PersonCombinedInfoInVote = vote.PersonCombinedInfo; VoteIneligibleReasonGuid = vote.InvalidReasonGuid; VoteStatusCode = vote.StatusCode; OnlineVoteRaw = vote.OnlineVoteRaw; //ballot BallotGuid = ballot.BallotGuid; BallotId = ballot.C_RowId; BallotStatusCode = ballot.StatusCode; C_BallotCode = ballot.C_BallotCode; //Location LocationId = location == null ? 0 : location.C_RowId; ElectionGuid = election.ElectionGuid; if (person != null) { AssertAtRuntime.That(person.PersonGuid == vote.PersonGuid); new PeopleModel().ApplyVoteReasonFlags(person); PersonId = person.C_RowId; PersonFullNameFL = person.FullNameAndArea; PersonFullName = person.C_FullName; PersonCombinedInfo = person.CombinedInfo; PersonIneligibleReasonGuid = person.IneligibleReasonGuid; PersonCanReceiveVotes = person.CanReceiveVotes.AsBoolean(); PersonGuid = person.PersonGuid; } else { PersonCanReceiveVotes = false; } }
public void AddBallotToDb(Ballot item) { Ballots.Add(item); }
public vBallotInfo CreateAndRegisterBallot() { var currentLocationGuid = UserSession.CurrentLocationGuid; var computerCode = UserSession.CurrentComputerCode; var ballot = new Ballot { BallotGuid = Guid.NewGuid(), LocationGuid = currentLocationGuid, ComputerCode = computerCode, BallotNumAtComputer = NextBallotNumAtComputer(), StatusCode = BallotStatusEnum.Empty, TellerAtKeyboard = UserSession.GetCurrentTeller(1), TellerAssisting = UserSession.GetCurrentTeller(2) }; Db.Ballots.Add(ballot); Db.SaveChanges(); SessionKey.CurrentBallotId.SetInSession(ballot.C_RowId); return Db.vBallotInfoes.Single(bi => bi.C_RowId == ballot.C_RowId); }
public bool BallotNeedsReview(Ballot ballot) { return ballot.StatusCode == BallotStatusEnum.Review; }
/// <Summary>Vote is not spoiled, so determine who this is...</Summary> private void ImportVotePerson(Ballot ballot, XmlElement voteXml, int voteNum) { var personXml = voteXml.SelectSingleNode("Person") as XmlElement; if (personXml == null) { // can't happen if XML is okay return; } Vote vote; var lastName = personXml.GetAttribute("LName"); var firstName = personXml.GetAttribute("FName"); var akaName = personXml.GetAttribute("AKAName"); // check for matches Person person; var matchedPeople = _people.Where(p => p.LastName.DefaultTo("") == lastName && p.FirstName.DefaultTo("") == firstName && p.OtherNames.DefaultTo("") == akaName).ToList(); var numMatched = matchedPeople.Count; switch (numMatched) { case 1: person = matchedPeople[0]; break; case 0: // vote is valid, but person not found! // is okay if we are loading without a community file if (lastName.HasNoContent() && firstName.HasNoContent()) { vote = new Vote { BallotGuid = ballot.BallotGuid, PositionOnBallot = voteNum, InvalidReasonGuid = IneligibleReasonEnum.Unreadable_Vote_is_blank, StatusCode = VoteHelper.VoteStatusCode.Ok }; _storeVote(vote); return; } else { person = new Person { PersonGuid = Guid.NewGuid(), ElectionGuid = _election.ElectionGuid, LastName = lastName, FirstName = firstName }; AddPerson(person); _people.Add(person); if (akaName.HasContent()) { person.OtherNames = akaName; } var bahaiId = personXml.GetAttribute("BahaiId"); if (bahaiId.HasContent()) { person.BahaiId = bahaiId; } var ineligible = personXml.GetAttribute("IneligibleToReceiveVotes").AsBoolean(); person.CanReceiveVotes = ineligible; var ineligibleReason = personXml.GetAttribute("ReasonToNotReceive").AsBoolean(); //TODO... } break; default: throw new ApplicationException("Name in Vote matches {0} {1}".FilledWith(numMatched, numMatched.Plural("person", "people"))); } // got the person vote = new Vote { BallotGuid = ballot.BallotGuid, PositionOnBallot = voteNum, PersonCombinedInfo = person.CombinedInfo, PersonGuid = person.PersonGuid, StatusCode = VoteHelper.VoteStatusCode.Ok }; _storeVote(vote); }
private void ImportVotes(Ballot ballot, XmlNodeList votesXml) { var voteNum = 0; foreach (XmlElement voteXml in votesXml) { var voteStatus = voteXml.GetAttribute("VoteStatus"); switch (voteStatus) { case "Spoiled": // 1.80 case "Ineligible": // 1.71 case "UnReadable": // 1.71 var spoiledGroup = voteXml.GetAttribute("SpoiledGroup").DefaultTo(voteStatus); var spoiledDetail = voteXml.GetAttribute("SpoiledDetail"); var ineligibleReasonGuid = MapIneligible(spoiledGroup, spoiledDetail); var vote = new Vote { BallotGuid = ballot.BallotGuid, PositionOnBallot = ++voteNum, InvalidReasonGuid = ineligibleReasonGuid, StatusCode = VoteHelper.VoteStatusCode.Ok }; _storeVote(vote); break; case "Ok": case "AddToList": case "New": default: ImportVotePerson(ballot, voteXml, ++voteNum); break; } } if (ballot.StatusCode == BallotStatusEnum.TooMany) { if (voteNum <= _election.NumberToElect) { // TallyJ v1 allowed user to choose "TooMany" and not enter too many votes... // TallyJ v2 want to see "too many" votes, so on import, add more to ensure status will be calculated as "TooMany" for (var i = _election.NumberToElect.AsInt() - voteNum; i >= 0; i--) { var vote = new Vote { BallotGuid = ballot.BallotGuid, PositionOnBallot = ++voteNum, InvalidReasonGuid = IneligibleReasonEnum.Ineligible_Other, StatusCode = VoteHelper.VoteStatusCode.Ok }; _storeVote(vote); } } } }
private void ImportBallots() { var ballotsXml = _xmlDoc.SelectNodes("//Ballot"); if (ballotsXml == null || ballotsXml.Count == 0) { return; } for (int i = 0, max = ballotsXml.Count; i < max; i++) { var ballotXml = ballotsXml[i] as XmlElement; var ballotId = ballotXml.GetAttribute("Id"); var ballotCodeInfo = ballotId.Split(new[] { '.' }); AssertAtRuntime.That(ballotCodeInfo.Length == 2, "Invalid ballot Id: " + ballotId); var ballot = new Ballot { LocationGuid = _location.LocationGuid, BallotGuid = Guid.NewGuid(), ComputerCode = ballotCodeInfo[0], BallotNumAtComputer = ballotCodeInfo[1].AsInt() }; // ignore automatic Ballot status, let this program determine actual status //var status = ballotXml.GetAttribute("BallotStatus"); var overrideStatus = ballotXml.GetAttribute("OverrideStatus"); switch (overrideStatus) { case "TooMany": ballot.StatusCode = BallotStatusEnum.TooMany; break; case "ReviewNeeded": ballot.StatusCode = BallotStatusEnum.Review; break; case "Normal": default: ballot.StatusCode = BallotStatusEnum.Ok; break; } _ballotsLoaded++; _storeBallot(ballot); ImportVotes(ballot, ballotXml.SelectNodes("Vote")); } }