reformated PollOptions

used HashSet for PollUsers
This commit is contained in:
Sarah Faey 2023-01-15 10:53:23 +01:00
parent 1f5a1f4fe2
commit 7e87500992
3 changed files with 36 additions and 19 deletions

View file

@ -73,11 +73,11 @@ namespace Lieb.Data
.FirstOrDefault(r => r.RaidId == raidId); .FirstOrDefault(r => r.RaidId == raidId);
if (raid == null) return 0; if (raid == null) return 0;
List<ulong> users = raid.SignUps.Where(s => s.LiebUserId != null).Select(s => (ulong)s.LiebUserId).ToList(); HashSet<ulong> users = raid.SignUps.Where(s => s.LiebUserId != null).Select(s => (ulong)s.LiebUserId).ToHashSet();
return await CreatePoll(poll, users, raidId); return await CreatePoll(poll, users, raidId);
} }
public async Task<int> CreatePoll(Poll poll, List<ulong> users, int? raidId = null) public async Task<int> CreatePoll(Poll poll, HashSet<ulong> users, int? raidId = null)
{ {
poll.RaidId = raidId; poll.RaidId = raidId;

View file

@ -193,7 +193,7 @@
} }
else if(_pollType == POLL_TYPE_GROUP) else if(_pollType == POLL_TYPE_GROUP)
{ {
await PollService.CreatePoll(_poll, UserService.GetGroupMembers(_chosenRole).Select(u => u.Id).ToList()); await PollService.CreatePoll(_poll, UserService.GetGroupMembers(_chosenRole).Select(u => u.Id).ToHashSet());
} }
NavigationManager.NavigateTo("polloverview"); NavigationManager.NavigateTo("polloverview");

View file

@ -10,23 +10,24 @@
@inject NavigationManager NavigationManager @inject NavigationManager NavigationManager
<body> <body>
<div @onclick="() => _isCollapsed = !_isCollapsed">
<div @onclick="() => _isCollapsed = !_isCollapsed"> <h5>@_poll.Question</h5>
@if(_raid != null)
<h5>@_poll.Question</h5>
@if(_raid != null)
{
<p>@_raid.Title - @_raid.StartTimeUTC.DateTime.ToLongDateString()</p>
}
</div>
@if (!_isCollapsed)
{
@foreach(var answer in _poll.Answers.GroupBy(a => a.Answer))
{ {
<p>@answer.Key - @answer.Count() </p> <p>@_raid.Title - @_raid.StartTimeUTC.DateTime.ToLongDateString()</p>
} }
}
@if (!_isCollapsed)
{
@foreach(var answer in Answers)
{
<p>@answer.Key - @answer.Value </p>
}
}
<br/>
<p>Not Answered - @_poll.Answers.Where(a => string.IsNullOrWhiteSpace(a.Answer)).Count() </p>
</div>
</body> </body>
@code { @code {
@ -36,9 +37,11 @@
[Parameter] [Parameter]
public LiebUser? _user { get; set; } public LiebUser? _user { get; set; }
public Raid _raid { get; set; } private Raid _raid { get; set; }
bool _isCollapsed = true; private bool _isCollapsed = true;
private Dictionary<string, int> Answers = new Dictionary<string, int>();
protected override async Task OnParametersSetAsync() protected override async Task OnParametersSetAsync()
{ {
@ -46,6 +49,20 @@
{ {
_raid = RaidService.GetRaid(_poll.RaidId.Value); _raid = RaidService.GetRaid(_poll.RaidId.Value);
} }
foreach(PollOption option in _poll.Options)
{
if(!Answers.ContainsKey(option.Name))
Answers.Add(option.Name, 0);
}
foreach(PollAnswer answer in _poll.Answers)
{
if(!string.IsNullOrWhiteSpace(answer.Answer))
{
if(!Answers.ContainsKey(answer.Answer))
Answers.Add(answer.Answer, 0);
Answers[answer.Answer] ++;
}
}
} }
} }