public int AddVoter(Voter v)
 {
     if (GetVoterByUid(v.GetUid()) != null)
     {
         Log.PrintLog("Fail. Voter UID already exist.");
         return -1;
     }
     VoterList.Add(v);
     Log.PrintLog("Successfully added Voter: " + v.GetUid());
     return 0;
 }
Exemple #2
0
        public int vote(string wechatid, int id)
        {
            if (!started)
            {
                return -1;
            }

            Voter currentVoter = new Voter(wechatid);
            currentEvent.AddVoter(currentVoter);
            return currentEvent.MakeVote(currentVoter, currentEvent.GetCandidateByUid(id));
        }
 public int MakeVote(Voter v, Candidate c)
 {
     if (restricted)
     {
         if (!IsExist(v, RestrictList))
         {
             Log.PrintLog("Voter does not exist in the list.");
             return -1;
         }
     }
     Vote myVote = new Vote(this, v, c.GetUid());
     if (HasVote(v))
     {
         VoteList.Add(myVote);
         GetVoteByVoter(v).GetCandidate().DeleteVote();
         VoteList.Remove(GetVoteByVoter(v));
         c.AddVote(myVote);
         v.voted = c;
         Log.PrintLog("Already voted. Overwritten.");
         return 1;
     }
     VoteList.Add(myVote);
     c.AddVote(myVote);
     v.voted = c;
     Log.PrintLog("Vote Success. Voter: " + v.GetUid() + " Candidate: " + c.GetUid());
     return 0;
 }
 public bool IsExist(Voter p, List<Voter> l)
 {
     for (int i = 0; i < l.Count; i++)
     {
         if (p.Equals(l[i]))
         {
             return true;
         }
     }
     return false;
 }
 public bool HasVote(Voter v)
 {
     for (int i = 0; i < VoteList.Count; i++)
     {
         if (VoteList[i].GetVoter().GetUid() == v.GetUid())
         {
             return true;
         }
     }
     return false;
 }
 public Vote GetVoteByVoter(Voter v)
 {
     if (v == null)
     {
         return null;
     }
     for (int i = 0; i < VoteList.Count; i++)
     {
         if (VoteList[i].GetVoter().Equals(v))
         {
             return VoteList[i];
         }
     }
     return null;
 }