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