Random Raid Role is no longer falesly deleted

This commit is contained in:
t.ruspekhofer 2022-03-13 23:38:18 +01:00
parent e22eea7fca
commit 8d443781a4
3 changed files with 16 additions and 2 deletions

View file

@ -103,9 +103,12 @@ namespace Lieb.Data
{
Dictionary<int, GuildWars2Build> signedUpUsers= new Dictionary<int, GuildWars2Build>();
foreach (RaidSignUp signUp in raid.SignUps)
{
if (signUp.GuildWars2Account.EquippedBuilds.Count > 0)
{
signedUpUsers.Add(signUp.LiebUserId, signUp.GuildWars2Account.EquippedBuilds.ToList()[_random.Next(signUp.GuildWars2Account.EquippedBuilds.Count - 1)].GuildWars2Build);
}
}
BalanceRoles(raid, signedUpUsers);
foreach(var userBuild in signedUpUsers)
{
@ -326,7 +329,7 @@ namespace Lieb.Data
List<PlannedRaidRole> rolesToDelete = new List<PlannedRaidRole>();
foreach (PlannedRaidRole role in raid.Roles)
{
if (raid.SignUps.FirstOrDefault(s => s.PlannedRaidRoleId == role.PlannedRaidRoleId) == null)
if (!role.IsRandomSignUpRole && raid.SignUps.FirstOrDefault(s => s.PlannedRaidRoleId == role.PlannedRaidRoleId) == null)
{
rolesToDelete.Add(role);
}

View file

@ -213,13 +213,23 @@ namespace Lieb.Data
public async Task SignOff(int raidId, int liebUserId)
{
using var context = _contextFactory.CreateDbContext();
//remove Flex Sign Ups
List<RaidSignUp> signUps = context.RaidSignUps.Where(x => x.RaidId == raidId && x.LiebUserId == liebUserId && x.SignUpType == SignUpType.Flex).ToList();
context.RaidSignUps.RemoveRange(signUps);
//change to SignedOff
RaidSignUp? signUp = context.RaidSignUps.FirstOrDefault(x => x.RaidId == raidId && x.LiebUserId == liebUserId && x.SignUpType != SignUpType.Flex);
if (signUp != null)
{
signUp.SignUpType = SignUpType.SignedOff;
//change and delete Role for Random Raids
Raid? raid = context.Raids.Include(r => r.Roles).FirstOrDefault(r => r.RaidId == raidId);
if(raid != null && raid.RaidType != RaidType.Planned && !signUp.PlannedRaidRole.IsRandomSignUpRole)
{
context.PlannedRaidRoles.Remove(signUp.PlannedRaidRole);
signUp.PlannedRaidRole = raid.Roles.FirstOrDefault(r => r.IsRandomSignUpRole);
}
}
await context.SaveChangesAsync();

View file

@ -62,6 +62,7 @@ namespace Lieb.Data
using var context = _contextFactory.CreateDbContext();
return context.LiebUsers
.Include(u => u.GuildWars2Accounts)
.ThenInclude(a => a.EquippedBuilds)
.FirstOrDefault(u => u.DiscordUserId == discordId);
}
else