Example #1
0
 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;
 }
Example #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));
        }
Example #3
0
 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;
 }
Example #4
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;
 }
Example #5
0
 public bool HasVote(Voter v)
 {
     for (int i = 0; i < VoteList.Count; i++)
     {
         if (VoteList[i].GetVoter().GetUid() == v.GetUid())
         {
             return true;
         }
     }
     return false;
 }
Example #6
0
 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;
 }