added poll pages

This commit is contained in:
Sarah Faey 2023-01-14 21:04:01 +01:00
parent 6d6e720695
commit 1158aff6df
8 changed files with 340 additions and 14 deletions

View file

@ -15,6 +15,15 @@ namespace Lieb.Data
_discordService = discordService;
}
public List<Poll> GetPolls()
{
using var context = _contextFactory.CreateDbContext();
return context.Polls
.Include(p => p.Options)
.Include(p => p.Answers)
.ToList();
}
public Poll GetPoll(int pollId)
{
using var context = _contextFactory.CreateDbContext();
@ -38,23 +47,13 @@ namespace Lieb.Data
}
public async Task<int> CreatePoll(string question, List<string> options, int raidId)
{
using var context = _contextFactory.CreateDbContext();
Raid? raid = context.Raids
.Include(r => r.SignUps)
.FirstOrDefault(r => r.RaidId == raidId);
if (raid == null) return 0;
List<ulong> users = raid.SignUps.Where(s => s.LiebUserId != null).Select(s => (ulong)s.LiebUserId).ToList();
return await CreatePoll(question, options, users, raidId);
}
public async Task<int> CreatePoll(string question, List<string> options, List<ulong> users, int? raidId = null)
{
Poll poll = new Poll()
{
Question = question,
RaidId = raidId
RaidId = raidId,
AllowCustomAnswer = false,
AnswerType = AnswerType.Buttons
};
foreach(string option in options)
{
@ -63,6 +62,25 @@ namespace Lieb.Data
Name = option
});
}
return await CreatePoll(poll, raidId);
}
public async Task<int> CreatePoll(Poll poll, int raidId)
{
using var context = _contextFactory.CreateDbContext();
Raid? raid = context.Raids
.Include(r => r.SignUps)
.FirstOrDefault(r => r.RaidId == raidId);
if (raid == null) return 0;
List<ulong> users = raid.SignUps.Where(s => s.LiebUserId != null).Select(s => (ulong)s.LiebUserId).ToList();
return await CreatePoll(poll, users, raidId);
}
public async Task<int> CreatePoll(Poll poll, List<ulong> users, int? raidId = null)
{
poll.RaidId = raidId;
foreach(ulong user in users)
{
poll.Answers.Add(new PollAnswer()

View file

@ -357,5 +357,15 @@ namespace Lieb.Data
await context.SaveChangesAsync();
return true;
}
public List<LiebUser> GetGroupMembers(int roleId)
{
using var context = _contextFactory.CreateDbContext();
return context.LiebUsers
.Include(u => u.RoleAssignments)
.ThenInclude(r => r.LiebRole)
.Where(u => u.RoleAssignments.Where(r => r.LiebRole.LiebRoleId == roleId).Any())
.ToList();
}
}
}