37 lines
670 B
C#
37 lines
670 B
C#
namespace back.DataModels;
|
|
|
|
public class RankingModel
|
|
{
|
|
private int totalVotes;
|
|
private int upVotes;
|
|
private int downVotes;
|
|
|
|
public RankingModel(int totalVotes, int upVotes = 0, int downVotes = 0)
|
|
{
|
|
this.totalVotes = totalVotes;
|
|
this.upVotes = upVotes;
|
|
this.downVotes = downVotes;
|
|
}
|
|
|
|
public void DownVote()
|
|
{
|
|
downVotes++;
|
|
totalVotes++;
|
|
}
|
|
|
|
public void UpVote()
|
|
{
|
|
upVotes++;
|
|
totalVotes++;
|
|
}
|
|
|
|
public double Score
|
|
{
|
|
get
|
|
{
|
|
if (totalVotes == 0) return 0;
|
|
return (double)(upVotes - downVotes) / totalVotes;
|
|
}
|
|
}
|
|
}
|