using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; namespace back.DataModels; [Table("Rankings")] public class RankingModel { [Key] public string Id { get; set; } = Guid.NewGuid().ToString(); 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 RankingModel() { totalVotes = 0; upVotes = 0; downVotes = 0; } public void DownVote() { downVotes++; totalVotes++; } public void UpVote() { upVotes++; totalVotes++; } public double Score { get { if (totalVotes == 0) return 0; return (double)(upVotes - downVotes) / totalVotes; } } }