users joining raids are now added to polls
added testsystem
This commit is contained in:
parent
ef1c301c05
commit
d9da5572a2
9 changed files with 1070 additions and 0 deletions
|
@ -109,5 +109,37 @@ namespace Lieb.Data
|
|||
PollAnswer answer = poll.Answers.First(a => a.UserId == userId);
|
||||
answer.PollOptionId = pollOptionId;
|
||||
}
|
||||
|
||||
public async Task AddUser(int pollId, ulong userId)
|
||||
{
|
||||
using var context = _contextFactory.CreateDbContext();
|
||||
Poll? poll = context.Polls
|
||||
.Include(p => p.Answers)
|
||||
.FirstOrDefault(p => p.PollId == pollId && p.Answers.Where(a => a.UserId == userId).Any());
|
||||
|
||||
if (poll == null) return;
|
||||
|
||||
poll.Answers.Add(new PollAnswer()
|
||||
{
|
||||
UserId = userId
|
||||
});
|
||||
await context.SaveChangesAsync();
|
||||
}
|
||||
|
||||
public async Task RemoveUser(int pollId, ulong userId)
|
||||
{
|
||||
using var context = _contextFactory.CreateDbContext();
|
||||
Poll? poll = context.Polls
|
||||
.Include(p => p.Answers)
|
||||
.FirstOrDefault(p => p.PollId == pollId && p.Answers.Where(a => a.UserId == userId).Any());
|
||||
|
||||
if (poll == null) return;
|
||||
|
||||
PollAnswer answer = poll.Answers.First(a => a.UserId == userId);
|
||||
context.Remove(answer);
|
||||
await context.SaveChangesAsync();
|
||||
poll.Answers.Remove(answer);
|
||||
await context.SaveChangesAsync();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -166,6 +166,10 @@ namespace Lieb.Data
|
|||
{
|
||||
return false;
|
||||
}
|
||||
foreach(Poll poll in context.Polls.Where(p => p.RaidId == raidId && !p.Answers.Where(a => a.UserId == liebUserId).Any()))
|
||||
{
|
||||
await _pollService.AddUser(poll.PollId, liebUserId);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -202,6 +206,10 @@ namespace Lieb.Data
|
|||
context.RaidSignUps.Add(signUp);
|
||||
}
|
||||
await context.SaveChangesAsync();
|
||||
foreach(Poll poll in context.Polls.Where(p => p.RaidId == raidId && !p.Answers.Where(a => a.UserId == liebUserId).Any()))
|
||||
{
|
||||
await _pollService.AddUser(poll.PollId, liebUserId);
|
||||
}
|
||||
await LogSignUp(signUp, userName, signedUpByUserId);
|
||||
return true;
|
||||
}
|
||||
|
@ -240,6 +248,10 @@ namespace Lieb.Data
|
|||
await LogSignUp(signUp, signUp.LiebUser.Name, signedOffByUserId);
|
||||
}
|
||||
await context.SaveChangesAsync();
|
||||
foreach(Poll poll in context.Polls.Where(p => p.RaidId == raidId && !p.Answers.Where(a => a.UserId == liebUserId).Any()))
|
||||
{
|
||||
await _pollService.RemoveUser(poll.PollId, liebUserId);
|
||||
}
|
||||
await _discordService.PostRaidMessage(raidId);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue