| | | 1 | | using MUNity.Base; |
| | | 2 | | using System; |
| | | 3 | | using System.Collections.Generic; |
| | | 4 | | using System.Linq; |
| | | 5 | | using System.Text; |
| | | 6 | | |
| | | 7 | | namespace MUNity.Schema.Simulation.Voting |
| | | 8 | | { |
| | | 9 | | public class SimulationVotingDto |
| | | 10 | | { |
| | | 11 | | public string VotingId { get; set; } |
| | | 12 | | |
| | | 13 | | public string Name { get; set; } |
| | | 14 | | |
| | | 15 | | public string Description { get; set; } |
| | | 16 | | |
| | | 17 | | public bool AllowAbstention { get; set; } |
| | | 18 | | |
| | | 19 | | public List<SimulationVoteSlotDto> Slots { get; set; } = new List<SimulationVoteSlotDto>(); |
| | | 20 | | |
| | | 21 | | public int TotalValidVotes => Slots.Count(n => n.Choice == EVoteStates.Pro || n.Choice == EVoteStates.Con); |
| | | 22 | | |
| | | 23 | | public int TotalGivenVotes => Slots.Count(n => n.Choice != EVoteStates.NotVoted); |
| | | 24 | | |
| | | 25 | | public int ProVotes => Slots.Count(n => n.Choice == EVoteStates.Pro); |
| | | 26 | | |
| | | 27 | | public int ConVotes => Slots.Count(n => n.Choice == EVoteStates.Con); |
| | | 28 | | |
| | | 29 | | public int AbstentionVotes => Slots.Count(n => n.Choice == EVoteStates.Abstention); |
| | | 30 | | |
| | | 31 | | public double ProPercentageOverall |
| | | 32 | | { |
| | | 33 | | get |
| | | 34 | | { |
| | | 35 | | if (Slots == null || Slots.Count == 0) |
| | | 36 | | return 0; |
| | | 37 | | return Math.Round(ProVotes / (double)Slots.Count * 100, 2); |
| | | 38 | | } |
| | | 39 | | } |
| | | 40 | | |
| | | 41 | | public double ConPercentageOverall |
| | | 42 | | { |
| | | 43 | | get |
| | | 44 | | { |
| | | 45 | | if (Slots == null || Slots.Count == 0) |
| | | 46 | | return 0; |
| | | 47 | | return Math.Round(ConVotes / (double)Slots.Count * 100, 2); |
| | | 48 | | } |
| | | 49 | | } |
| | | 50 | | |
| | | 51 | | public double AbstentionPercentageOverall |
| | | 52 | | { |
| | | 53 | | get |
| | | 54 | | { |
| | | 55 | | if (Slots == null || Slots.Count == 0) |
| | | 56 | | return 0; |
| | | 57 | | return Math.Round(AbstentionVotes / (double)Slots.Count * 100, 2); |
| | | 58 | | } |
| | | 59 | | } |
| | | 60 | | |
| | | 61 | | public double ProPercentage |
| | | 62 | | { |
| | | 63 | | get |
| | | 64 | | { |
| | | 65 | | if (this.TotalValidVotes == 0) return 0; |
| | | 66 | | return Math.Round(this.ProVotes / (double)this.TotalValidVotes * 100, 2); |
| | | 67 | | } |
| | | 68 | | } |
| | | 69 | | |
| | | 70 | | public double ConPercentage |
| | | 71 | | { |
| | | 72 | | get |
| | | 73 | | { |
| | | 74 | | if (this.TotalValidVotes == 0) return 0; |
| | | 75 | | return Math.Round(this.ConVotes / (double)this.TotalValidVotes * 100, 2); |
| | | 76 | | } |
| | | 77 | | } |
| | | 78 | | } |
| | | 79 | | |
| | | 80 | | public class SimulationVoteSlotDto |
| | | 81 | | { |
| | 0 | 82 | | public int SimulationVoteSlotId { get; set; } |
| | | 83 | | |
| | 0 | 84 | | public int SimulationUserId { get; set; } |
| | | 85 | | |
| | 0 | 86 | | public string DisplayName { get; set; } |
| | | 87 | | |
| | 0 | 88 | | public string RoleName { get; set; } |
| | | 89 | | |
| | 0 | 90 | | public EVoteStates Choice { get; set; } |
| | | 91 | | |
| | 0 | 92 | | public DateTime? VoteTime { get; set; } |
| | | 93 | | } |
| | | 94 | | } |