/// <summary> /// Calcula os votos /// </summary> /// <param name="t"></param> /// <returns></returns> public int CalcVotes(TargetVote.Vote t) { int count = 0; votesInt = null; for (int i = 0; i < votes.Count; i++) { if (votes[i].vote == t) { count++; } } return(count); }
/// <summary> /// Pega o voto para o usuário /// </summary> /// <param name="userid"></param> /// <returns></returns> public bool SetUserVote(string userid, TargetVote.Vote v) { TargetVote.Vote vo = GetUserVote(userid); if (vo == v) { v = TargetVote.Vote.Undefined; } if (v == TargetVote.Vote.Undefined) { for (int i = 0; i < votes.Count; i++) { if (votes[i].userId == userid) { votes.RemoveAt(i); return(false); } } } else { for (int i = 0; i < votes.Count; i++) { if (votes[i].userId == userid) { votes[i].vote = v; votes[i].date = DateTime.Now; return(false); } } TargetVote vote = new TargetVote(this); vote.userId = userid; vote.vote = v; vote.date = DateTime.Now; votes.Add(vote); return(true); } return(false); }