-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathVotingOption.cs
59 lines (52 loc) · 1.42 KB
/
VotingOption.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
namespace VoteR
{
using System.Collections.Generic;
using System.Linq;
public class VotingOption
{
public VotingOption(string name)
{
this.Name = name;
this.Voters = new HashSet<string>();
}
/// <summary>
/// Voting option name.
/// </summary>
public string Name { get; set; }
/// <summary>
/// Gets the number of votes for this option.
/// </summary>
public int Votes
{
get
{
return Voters.Count();
}
}
/// <summary>
/// HashSet of connection ids that have voted for this option.
/// </summary>
private HashSet<string> Voters { get; set; }
public bool UserHasVoted(string cid)
{
return Voters.Contains(cid);
}
/// <summary>
/// Removes a votes from the option.
/// </summary>
/// <param name="cid">Id of the voter.</param>
/// <returns>True if the voter was removed, otherwise false.</returns>
public bool RemoveVoter(string cid)
{
return Voters.Remove(cid);
}
/// <summary>
/// Adds a voter to the option.
/// </summary>
/// <param name="cid">Id of the voter.</param>
public void AddVoter(string cid)
{
Voters.Add(cid);
}
}
}