From 212e1a393d41c51f8bba352946a3a1ebf2446804 Mon Sep 17 00:00:00 2001 From: "t.ruspekhofer" Date: Mon, 14 Mar 2022 22:21:10 +0100 Subject: [PATCH] no tusable SignUp Buttons are now disabled --- Lieb/Data/RaidService.cs | 51 +++++++++++++++----- Lieb/Pages/Raids/RaidRoles.razor | 80 +++++++++++++------------------- 2 files changed, 71 insertions(+), 60 deletions(-) diff --git a/Lieb/Data/RaidService.cs b/Lieb/Data/RaidService.cs index c8bc132..e84ba7f 100644 --- a/Lieb/Data/RaidService.cs +++ b/Lieb/Data/RaidService.cs @@ -185,7 +185,7 @@ namespace Lieb.Data public async Task SignUp(int raidId, int liebUserId, int guildWars2AccountId, int plannedRoleId, SignUpType signUpType) { - if (!await IsRoleSignUpAllowed(raidId, liebUserId, plannedRoleId, signUpType, true, new List())) + if (!IsRoleSignUpAllowed(raidId, liebUserId, plannedRoleId, signUpType, true)) { return; } @@ -248,7 +248,7 @@ namespace Lieb.Data public async Task ChangeSignUpType(int raidId, int liebUserId, int plannedRoleId, SignUpType signUpType) { - if (!await IsRoleSignUpAllowed(raidId, liebUserId, plannedRoleId, signUpType, true, new List())) + if (!IsRoleSignUpAllowed(raidId, liebUserId, plannedRoleId, signUpType, true)) { return; } @@ -301,10 +301,43 @@ namespace Lieb.Data public bool IsRoleSignUpAllowed(int raidId, int liebUserId, int plannedRoleId, SignUpType signUpType, bool moveFlexUser) { - return IsRoleSignUpAllowed(raidId, liebUserId, plannedRoleId, signUpType, moveFlexUser, new List()).Result; + using var context = _contextFactory.CreateDbContext(); + Raid? raid = context.Raids + .Include(r => r.Roles) + .Include(r => r.SignUps) + .FirstOrDefault(r => r.RaidId == raidId); + + if (raid == null) return false; + + if (raid.RaidType == RaidType.Planned) + { + //if (raid.MoveFlexAllowed) + { + return IsRoleSignUpAllowed(raid, liebUserId, plannedRoleId, signUpType, moveFlexUser, new List()).Result; + } + //else + //{ + // return IsRoleSignUpAllowed(liebUserId, plannedRoleId, signUpType); + //} + } + else + { + PlannedRaidRole? role = context.PlannedRaidRoles + .AsNoTracking() + .FirstOrDefault(r => r.PlannedRaidRoleId == plannedRoleId); + if(role == null) return false; + if (role.IsRandomSignUpRole) + { + // new sign up is available if there are free spots and the user is not signed up or still in the random role + RaidSignUp? signUp = raid.SignUps.FirstOrDefault(s => s.LiebUserId == liebUserId); + return raid.SignUps.Where(s => s.SignUpType == SignUpType.SignedUp).Count() < role.Spots + && (signUp == null || signUp.PlannedRaidRoleId == plannedRoleId || signUp.SignUpType == SignUpType.SignedOff); + } + return raid.SignUps.Where(s => s.LiebUserId == liebUserId && s.PlannedRaidRoleId == plannedRoleId).Any(); + } } - private async Task IsRoleSignUpAllowed(int raidId, int liebUserId, int plannedRoleId, SignUpType signUpType, bool moveFlexUser, List checkedRoleIds) + private async Task IsRoleSignUpAllowed(Raid raid, int liebUserId, int plannedRoleId, SignUpType signUpType, bool moveFlexUser, List checkedRoleIds) { if (IsRoleSignUpAllowed(liebUserId, plannedRoleId, signUpType)) return true; @@ -313,12 +346,6 @@ namespace Lieb.Data checkedRoleIds = new List(); checkedRoleIds.Add(plannedRoleId); - using var context = _contextFactory.CreateDbContext(); - Raid? raid = context.Raids - .Include(r => r.Roles) - .Include(r => r.SignUps) - .FirstOrDefault(r => r.RaidId == raidId); - if (raid == null) { return false; @@ -329,11 +356,11 @@ namespace Lieb.Data foreach (RaidSignUp signUp in raid.SignUps.Where(s => s.LiebUserId == userId && s.SignUpType == SignUpType.Flex)) { if (!checkedRoleIds.Contains(signUp.PlannedRaidRoleId) - && await IsRoleSignUpAllowed(raidId, userId, signUp.PlannedRaidRoleId, SignUpType.SignedUp, moveFlexUser, checkedRoleIds)) + && await IsRoleSignUpAllowed(raid, userId, signUp.PlannedRaidRoleId, SignUpType.SignedUp, moveFlexUser, checkedRoleIds)) { if (moveFlexUser) { - await ChangeSignUpType(raidId, userId, signUp.PlannedRaidRoleId, SignUpType.SignedUp); + await ChangeSignUpType(raid.RaidId, userId, signUp.PlannedRaidRoleId, SignUpType.SignedUp); } return true; } diff --git a/Lieb/Pages/Raids/RaidRoles.razor b/Lieb/Pages/Raids/RaidRoles.razor index 146465b..d66ce9e 100644 --- a/Lieb/Pages/Raids/RaidRoles.razor +++ b/Lieb/Pages/Raids/RaidRoles.razor @@ -18,61 +18,45 @@ @role.Name (@usedSpots /@role.Spots)
@role.Description - @foreach (var signUp in signUps) - { - @if(signUp.SignUpType != SignUpType.SignedOff) + + @foreach (var signUp in signUps) { - - @{bool isUser = isSignedUp && userRole.PlannedRaidRole.PlannedRaidRoleId == role.PlannedRaidRoleId && signUp.LiebUserId == _liebUserId;} - @{string signUpStatus = string.Empty;} - @if (signUp.SignUpType != SignUpType.SignedUp) signUpStatus = $" - {signUp.SignUpType}"; + @if(signUp.SignUpType != SignUpType.SignedOff) + { + + @{bool isUser = isSignedUp && userRole.PlannedRaidRole.PlannedRaidRoleId == role.PlannedRaidRoleId && signUp.LiebUserId == _liebUserId;} + @{string signUpStatus = string.Empty;} + @if (signUp.SignUpType != SignUpType.SignedUp) signUpStatus = $" - {signUp.SignUpType}"; - @if (isUser && _usableAccounts.Count > 1) - { - - } - else - { - - } - + @if (isUser && _usableAccounts.Count > 1) + { + + } + else + { + + } + + } } - } +
@signUp.LiebUser.Name - @signUpStatus @signUp.LiebUser.Name (@signUp.GuildWars2Account.AccountName) @signUpStatus
@signUp.LiebUser.Name + @signUpStatus @signUp.LiebUser.Name (@signUp.GuildWars2Account.AccountName) @signUpStatus
@if(_liebUserId > 0) { - @if(_raid.RaidType == RaidType.Planned) + bool notIsRoleSignUpAllowed = !RaidService.IsRoleSignUpAllowed(_raid.RaidId, _user.LiebUserId, role.PlannedRaidRoleId, SignUpType.SignedUp, false); + bool notIsBackupAllowed = _raid.RaidType != RaidType.Planned && notIsRoleSignUpAllowed; + + + + @if (isSignedUp && userRole.SignUpType != SignUpType.SignedOff && _raid.RaidType == RaidType.Planned) { - @if (RaidService.IsRoleSignUpAllowed(_raid.RaidId, _user.LiebUserId, role.PlannedRaidRoleId, SignUpType.SignedUp, false)) - { - - - } - else - { - - - } - - @if (isSignedUp && userRole.SignUpType != SignUpType.SignedOff && _raid.RaidType == RaidType.Planned) - { - - } - } - else - { - @if (role.IsRandomSignUpRole && _raid.SignUps.Where(s => s.SignUpType == SignUpType.SignedUp).Count() < role.Spots) - { - - - - } + } }