From 8d443781a4a1cff30d1f6d665c5070971aa0958b Mon Sep 17 00:00:00 2001 From: "t.ruspekhofer" Date: Sun, 13 Mar 2022 23:38:18 +0100 Subject: [PATCH] Random Raid Role is no longer falesly deleted --- Lieb/Data/RaidRandomizerService.cs | 7 +++++-- Lieb/Data/RaidService.cs | 10 ++++++++++ Lieb/Data/UserService.cs | 1 + 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/Lieb/Data/RaidRandomizerService.cs b/Lieb/Data/RaidRandomizerService.cs index 98816e1..9a0db66 100644 --- a/Lieb/Data/RaidRandomizerService.cs +++ b/Lieb/Data/RaidRandomizerService.cs @@ -104,7 +104,10 @@ namespace Lieb.Data Dictionary signedUpUsers= new Dictionary(); foreach (RaidSignUp signUp in raid.SignUps) { - signedUpUsers.Add(signUp.LiebUserId, signUp.GuildWars2Account.EquippedBuilds.ToList()[_random.Next(signUp.GuildWars2Account.EquippedBuilds.Count - 1)].GuildWars2Build); + 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 rolesToDelete = new List(); 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); } diff --git a/Lieb/Data/RaidService.cs b/Lieb/Data/RaidService.cs index 3775598..c8bc132 100644 --- a/Lieb/Data/RaidService.cs +++ b/Lieb/Data/RaidService.cs @@ -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 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(); diff --git a/Lieb/Data/UserService.cs b/Lieb/Data/UserService.cs index 60b5bcb..89588e4 100644 --- a/Lieb/Data/UserService.cs +++ b/Lieb/Data/UserService.cs @@ -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