Random Raid Role is no longer falesly deleted
This commit is contained in:
parent
e22eea7fca
commit
8d443781a4
3 changed files with 16 additions and 2 deletions
|
@ -103,9 +103,12 @@ namespace Lieb.Data
|
||||||
{
|
{
|
||||||
Dictionary<int, GuildWars2Build> signedUpUsers= new Dictionary<int, GuildWars2Build>();
|
Dictionary<int, GuildWars2Build> signedUpUsers= new Dictionary<int, GuildWars2Build>();
|
||||||
foreach (RaidSignUp signUp in raid.SignUps)
|
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);
|
signedUpUsers.Add(signUp.LiebUserId, signUp.GuildWars2Account.EquippedBuilds.ToList()[_random.Next(signUp.GuildWars2Account.EquippedBuilds.Count - 1)].GuildWars2Build);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
BalanceRoles(raid, signedUpUsers);
|
BalanceRoles(raid, signedUpUsers);
|
||||||
foreach(var userBuild in signedUpUsers)
|
foreach(var userBuild in signedUpUsers)
|
||||||
{
|
{
|
||||||
|
@ -326,7 +329,7 @@ namespace Lieb.Data
|
||||||
List<PlannedRaidRole> rolesToDelete = new List<PlannedRaidRole>();
|
List<PlannedRaidRole> rolesToDelete = new List<PlannedRaidRole>();
|
||||||
foreach (PlannedRaidRole role in raid.Roles)
|
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);
|
rolesToDelete.Add(role);
|
||||||
}
|
}
|
||||||
|
|
|
@ -213,13 +213,23 @@ namespace Lieb.Data
|
||||||
public async Task SignOff(int raidId, int liebUserId)
|
public async Task SignOff(int raidId, int liebUserId)
|
||||||
{
|
{
|
||||||
using var context = _contextFactory.CreateDbContext();
|
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();
|
List<RaidSignUp> signUps = context.RaidSignUps.Where(x => x.RaidId == raidId && x.LiebUserId == liebUserId && x.SignUpType == SignUpType.Flex).ToList();
|
||||||
context.RaidSignUps.RemoveRange(signUps);
|
context.RaidSignUps.RemoveRange(signUps);
|
||||||
|
|
||||||
|
//change to SignedOff
|
||||||
RaidSignUp? signUp = context.RaidSignUps.FirstOrDefault(x => x.RaidId == raidId && x.LiebUserId == liebUserId && x.SignUpType != SignUpType.Flex);
|
RaidSignUp? signUp = context.RaidSignUps.FirstOrDefault(x => x.RaidId == raidId && x.LiebUserId == liebUserId && x.SignUpType != SignUpType.Flex);
|
||||||
if (signUp != null)
|
if (signUp != null)
|
||||||
{
|
{
|
||||||
signUp.SignUpType = SignUpType.SignedOff;
|
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();
|
await context.SaveChangesAsync();
|
||||||
|
|
|
@ -62,6 +62,7 @@ namespace Lieb.Data
|
||||||
using var context = _contextFactory.CreateDbContext();
|
using var context = _contextFactory.CreateDbContext();
|
||||||
return context.LiebUsers
|
return context.LiebUsers
|
||||||
.Include(u => u.GuildWars2Accounts)
|
.Include(u => u.GuildWars2Accounts)
|
||||||
|
.ThenInclude(a => a.EquippedBuilds)
|
||||||
.FirstOrDefault(u => u.DiscordUserId == discordId);
|
.FirstOrDefault(u => u.DiscordUserId == discordId);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue