Beispiel #1
0
        public void VoteFor(Candidate candidate, PersonName voter)
        {
            if (candidate is null)
            {
                throw new ArgumentNullException(nameof(candidate), "You must vote for an existing candidate.");
            }
            if (voter is null)
            {
                throw new ArgumentException(nameof(voter), "You must enter a voter first and last name.");
            }
            var duplicateBallot = _candidacies.SelectMany(x => x.Ballots).FirstOrDefault(y => y.Voter == voter);

            if (duplicateBallot != null)
            {
                throw new ArgumentException(nameof(voter), "Voter has already cast a ballot.");
            }

            var candidacyToAddVote = _candidacies.Find(x => x.Candidate == candidate);

            if (candidacyToAddVote != null)
            {
                var ballot = new Ballot(voter, candidacyToAddVote);
                candidacyToAddVote.AddBallot(ballot);
            }


            // Basic guards - null candidate, etc.
            // Is this candidate in this election?

            // Has this voter already submitted a ballot?

            // Find the candidacy

            // Create a new Ballot()

            // Add the Ballot to the candidacy's ballot list
        }
Beispiel #2
0
 public void AddBallot(Ballot ballot)
 {
     _ballots.Add(ballot);
 }