public void AddVoter(IVoter voter) { if (!voterDictionary.ContainsKey(voter.Name)) { voterDictionary[voter.Name] = voter; } }
public void AddVoterWithChoice(String voterName, String choice) { IVoter voter = findVoter(voterName).VoterItem; voter.Pick(choice); AddVoter(voter); }
/// <summary> /// Saves the current voter progress and his answers to the database /// </summary> public void SaveVoterProgress(VoterAnswersData voterAnswers) { IVoter voter = VoterFactory.Create(); VoterAnswersData data = new VoterAnswersData(); data.Merge(voterAnswers, false); voter.AddVoter(data); }
public void AddVoterWithDelegate(String voterName, String delegateName) { IVoter voter = findVoter(voterName).VoterItem; voter.DelegateToVoter = new Voter(delegateName); AddVoter(voter); AddVoter(voter.DelegateToVoter); }
FindVoterResult findVoter(IVoter voter) { String voterName = (voter != null) ? voter.Name : ""; if (voterDictionary.ContainsKey(voterName)) { return(new FindVoterResult(voterDictionary[voterName], true)); } return(new FindVoterResult(new Voter(voterName), false)); }
public void DelegateVote(IVoter fromWhom, IVoter toWhom) { FindVoterResult voterResult = findVoter(fromWhom); if (voterResult.IsFound) { voterResult.VoterItem.DelegateToVoter = toWhom; } else { fromWhom.DelegateToVoter = toWhom; AddVoter(fromWhom); } }
bool AreVotesInvalidForVoter(IVoter voter) { HashSet <IVoter> uniqueVoters = new HashSet <IVoter>(); FindVoterResult voterResult = findVoter(voter); while (voterResult.IsFound) { if (uniqueVoters.Contains(voterResult.VoterItem)) { return(true); } uniqueVoters.Add(voterResult.VoterItem); voterResult = findVoter(voterResult.VoterItem.DelegateToVoter); } return(false); }
public byte[] AddVote(List <uint> rawVoteData, IVoter voter) { if (rawVoteData.Any(v => !(v == 0 || v == 1))) { throw new ArgumentException("Allowed values are 0 and 1"); } if (rawVoteData.Sum(v => v) > 1) { rawVoteData = NullVote.ToList(); } var publicKey = homomorphicKeyManager.DeserializePublicKey(boothInit.HomomorphicPublicKey); List <byte[]> encryptedTexts = new List <byte[]>(); foreach (var candidate_vote in rawVoteData) { var encryptedVote = homomorphicKeyManager.Encrypt(publicKey, candidate_vote); encryptedTexts.Add(homomorphicKeyManager.SerializeCiphertext(encryptedVote)); } var serializedVote = SerializeList(encryptedTexts); Vote vote = new Vote { BoothPublicCertificate = signCertificate.GetPublicKey(), CandidateVotes = encryptedTexts, ID = voter.ID, DisplayName = voter.DisplayName }; vote.VoteSignature = signCertificate.Sign(vote.VoteHash); votes.Add(vote); return(vote.VoteHash); }
public PostController(ICrud <Post> pc, IVoter voter) { this.pc = pc; this.voter = voter; }
public FindVoterResult(IVoter voter, bool isFound) { VoterItem = voter; IsFound = isFound; }