reworked raid details
This commit is contained in:
parent
8afe8af4c5
commit
75b8fd13fc
3 changed files with 148 additions and 104 deletions
|
@ -1,4 +1,5 @@
|
|||
using Lieb.Models.GuildWars2.Raid;
|
||||
using Lieb.Models;
|
||||
using Lieb.Models.GuildWars2.Raid;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Lieb.Data
|
||||
|
@ -148,7 +149,7 @@ namespace Lieb.Data
|
|||
|
||||
public async Task SignUp(int raidId, int liebUserId, int guildWars2AccountId, int plannedRoleId, SignUpType signUpType)
|
||||
{
|
||||
if (!IsSignUpAllowed(liebUserId, plannedRoleId, signUpType))
|
||||
if (!await IsRoleSignUpAllowed(raidId, liebUserId, plannedRoleId, signUpType, true, new List<int>()))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
@ -195,7 +196,7 @@ namespace Lieb.Data
|
|||
|
||||
public async Task ChangeSignUpType(int raidId, int liebUserId, int plannedRoleId, SignUpType signUpType)
|
||||
{
|
||||
if (!IsSignUpAllowed(liebUserId, plannedRoleId, signUpType))
|
||||
if (!await IsRoleSignUpAllowed(raidId, liebUserId, plannedRoleId, signUpType, true, new List<int>()))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
@ -223,7 +224,7 @@ namespace Lieb.Data
|
|||
}
|
||||
}
|
||||
|
||||
public bool IsSignUpAllowed(int liebUserId, int plannedRoleId, SignUpType signUpType)
|
||||
public bool IsRoleSignUpAllowed(int liebUserId, int plannedRoleId, SignUpType signUpType)
|
||||
{
|
||||
if(signUpType == SignUpType.Backup || signUpType == SignUpType.Flex || signUpType == SignUpType.SignedOff)
|
||||
{
|
||||
|
@ -246,9 +247,14 @@ namespace Lieb.Data
|
|||
return signUps.Where(s => s.LiebUserId == liebUserId && s.SignUpType == SignUpType.SignedUp).Any();
|
||||
}
|
||||
|
||||
public async Task<bool> IsSignUpAllowed(int raidId, int liebUserId, int plannedRoleId, SignUpType signUpType, bool moveFlexUser, List<int> checkedRoleIds)
|
||||
public bool IsRoleSignUpAllowed(int raidId, int liebUserId, int plannedRoleId, SignUpType signUpType, bool moveFlexUser)
|
||||
{
|
||||
if (IsSignUpAllowed(liebUserId, plannedRoleId, signUpType))
|
||||
return IsRoleSignUpAllowed(raidId, liebUserId, plannedRoleId, signUpType, moveFlexUser, new List<int>()).Result;
|
||||
}
|
||||
|
||||
private async Task<bool> IsRoleSignUpAllowed(int raidId, int liebUserId, int plannedRoleId, SignUpType signUpType, bool moveFlexUser, List<int> checkedRoleIds)
|
||||
{
|
||||
if (IsRoleSignUpAllowed(liebUserId, plannedRoleId, signUpType))
|
||||
return true;
|
||||
|
||||
if (checkedRoleIds == null)
|
||||
|
@ -271,7 +277,7 @@ namespace Lieb.Data
|
|||
foreach (RaidSignUp signUp in raid.SignUps.Where(s => s.LiebUserId == userId && s.SignUpType == SignUpType.Flex))
|
||||
{
|
||||
if (!checkedRoleIds.Contains(signUp.PlannedRaidRoleId)
|
||||
&& await IsSignUpAllowed(raidId, userId, signUp.PlannedRaidRoleId, SignUpType.SignedUp, moveFlexUser, checkedRoleIds))
|
||||
&& await IsRoleSignUpAllowed(raidId, userId, signUp.PlannedRaidRoleId, SignUpType.SignedUp, moveFlexUser, checkedRoleIds))
|
||||
{
|
||||
if (moveFlexUser)
|
||||
{
|
||||
|
@ -283,5 +289,52 @@ namespace Lieb.Data
|
|||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool IsRaidSignUpAllowed(int liebUserId, int raidId, out string errorMessage)
|
||||
{
|
||||
errorMessage = string.Empty;
|
||||
using var context = _contextFactory.CreateDbContext();
|
||||
Raid? raid = context.Raids
|
||||
.AsNoTracking()
|
||||
.FirstOrDefault(r => r.RaidId == raidId);
|
||||
if(raid == null)
|
||||
{
|
||||
errorMessage = "Raid not found.";
|
||||
return false;
|
||||
}
|
||||
LiebUser? user = context.LiebUsers
|
||||
.Include(u => u.RoleAssignments)
|
||||
.ThenInclude(a => a.LiebRole)
|
||||
.Include(u => u.GuildWars2Accounts)
|
||||
.ThenInclude(a => a.EquippedBuilds)
|
||||
.AsNoTracking()
|
||||
.FirstOrDefault(r => r.LiebUserId == liebUserId);
|
||||
if (user == null)
|
||||
{
|
||||
errorMessage = "User not found.";
|
||||
return false;
|
||||
}
|
||||
|
||||
DateTime freeForAllTime = raid.FreeForAllDate.Date + raid.FreeForAllTime.TimeOfDay;
|
||||
if (!string.IsNullOrEmpty(raid.RequiredRole) && !user.RoleAssignments.Where(a => a.LiebRole.RoleName == raid.RequiredRole).Any() || freeForAllTime > DateTimeOffset.Now)
|
||||
{
|
||||
errorMessage = $"The raid is still locked for {raid.RequiredRole}.";
|
||||
return false;
|
||||
}
|
||||
|
||||
if (user.GuildWars2Accounts.Count == 0)
|
||||
{
|
||||
errorMessage = "No Guild Wars 2 account found.";
|
||||
return false;
|
||||
}
|
||||
|
||||
if (raid.RaidType != RaidType.Planned && !user.GuildWars2Accounts.Where(a => a.EquippedBuilds.Count > 0).Any())
|
||||
{
|
||||
errorMessage = "No equipped Guild Wars 2 build found.";
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -44,31 +44,31 @@
|
|||
LiebUser user = UserService.GetLiebUser(discordId);
|
||||
RaidSignUp userRole = _raid.SignUps.Where(s => s.LiebUserId == user.LiebUserId).FirstOrDefault();
|
||||
bool isSignedUp = userRole != null;
|
||||
DateTime flexTime = _raid.FreeForAllDate.Date + _raid.FreeForAllTime.TimeOfDay;
|
||||
bool isSignUoAllowed = !_raid.IsRandomized && (user.RoleAssignments.FirstOrDefault(a => a.LiebRole.RoleName == _raid.RequiredRole) != null || flexTime < DateTime.Now);
|
||||
isSignUoAllowed = isSignUoAllowed && user.GuildWars2Accounts.Count > 0 && (_raid.RaidType == RaidType.Planned || user.GuildWars2Accounts.FirstOrDefault()?.EquippedBuilds.Count > 0);
|
||||
|
||||
bool isRaidSignUpAllowed = RaidService.IsRaidSignUpAllowed(user.LiebUserId, _raid.RaidId, out string errorMessage);
|
||||
}
|
||||
<label>@errorMessage</label>
|
||||
<table class="table">
|
||||
<tbody>
|
||||
@foreach (var role in _raid.Roles)
|
||||
{
|
||||
Models.GuildWars2.Raid.RaidSignUp[] signUps = _raid.SignUps.Where(s => s.PlannedRaidRoleId == role.PlannedRaidRoleId).ToArray();
|
||||
RaidSignUp[] signUps = _raid.SignUps.Where(s => s.PlannedRaidRoleId == role.PlannedRaidRoleId).ToArray();
|
||||
int usedSpots = signUps.Where(s => s.SignUpType == SignUpType.SignedUp).Count();
|
||||
|
||||
<tr>
|
||||
@if (isSignUoAllowed)
|
||||
@if (isRaidSignUpAllowed)
|
||||
{
|
||||
@if (@usedSpots < @role.Spots)
|
||||
@if (RaidService.IsRoleSignUpAllowed(_raid.RaidId, user.LiebUserId, role.PlannedRaidRoleId, SignUpType.SignedUp, false))
|
||||
{
|
||||
<td><button @onclick="() => SignUpClicked(role, user, isSignedUp)">Sign Up</button></td>
|
||||
<td><button @onclick="() => MaybeClicked(role, user, isSignedUp)">Maybe</button></td>
|
||||
<td><button @onclick="() => SignUpClicked(role, user, isSignedUp, SignUpType.SignedUp)">Sign Up</button></td>
|
||||
<td><button @onclick="() => SignUpClicked(role, user, isSignedUp, SignUpType.Maybe)">Maybe</button></td>
|
||||
}
|
||||
else
|
||||
{
|
||||
<td></td>
|
||||
<td></td>
|
||||
}
|
||||
<td><button @onclick="() => BackupClicked(role, user, isSignedUp)">Backup</button></td>
|
||||
<td><button @onclick="() => SignUpClicked(role, user, isSignedUp, SignUpType.Backup)">Backup</button></td>
|
||||
<td><button @onclick="() => SignUpClicked(role, user, isSignedUp, SignUpType.Flex)">Flex</button></td>
|
||||
}
|
||||
<td><h5>@role.Name: @role.Description (@usedSpots /@role.Spots)</h5></td>
|
||||
</tr>
|
||||
|
@ -79,8 +79,9 @@
|
|||
{
|
||||
<tr>
|
||||
@{bool isUser = isSignedUp && userRole.PlannedRaidRole.PlannedRaidRoleId == role.PlannedRaidRoleId && signUp.LiebUserId == user.LiebUserId;}
|
||||
@if (isSignUoAllowed)
|
||||
@if (isRaidSignUpAllowed)
|
||||
{
|
||||
<td></td>
|
||||
<td></td>
|
||||
<td></td>
|
||||
@if(isUser)
|
||||
|
@ -115,7 +116,6 @@
|
|||
}
|
||||
</tbody>
|
||||
</table>
|
||||
}
|
||||
</Authorized>
|
||||
<NotAuthorized>
|
||||
<div>
|
||||
|
@ -165,41 +165,18 @@
|
|||
[Parameter]
|
||||
public Raid _raid { get; set; }
|
||||
|
||||
async Task SignUpClicked(PlannedRaidRole role, LiebUser liebUser, bool isSignedUp)
|
||||
{
|
||||
if(isSignedUp)
|
||||
{
|
||||
await RaidService.ChangeSignUpType(_raid.RaidId, liebUser.LiebUserId, role.PlannedRaidRoleId, SignUpType.SignedUp);
|
||||
}
|
||||
else
|
||||
{
|
||||
await RaidService.SignUp(_raid.RaidId, liebUser.LiebUserId, liebUser.GuildWars2Accounts.FirstOrDefault().GuildWars2AccountId, role.PlannedRaidRoleId, SignUpType.SignedUp);
|
||||
}
|
||||
_raid = RaidService.GetRaid(_raid.RaidId);
|
||||
}
|
||||
[Parameter]
|
||||
public LiebUser? _user { get; set; }
|
||||
|
||||
async Task BackupClicked(PlannedRaidRole role, LiebUser liebUser, bool isSignedUp)
|
||||
async Task SignUpClicked(PlannedRaidRole role, LiebUser liebUser, bool isSignedUp, SignUpType signUpType)
|
||||
{
|
||||
if(isSignedUp)
|
||||
{
|
||||
await RaidService.ChangeSignUpType(_raid.RaidId, liebUser.LiebUserId, role.PlannedRaidRoleId, SignUpType.Backup);
|
||||
await RaidService.ChangeSignUpType(_raid.RaidId, liebUser.LiebUserId, role.PlannedRaidRoleId, signUpType);
|
||||
}
|
||||
else
|
||||
{
|
||||
await RaidService.SignUp(_raid.RaidId, liebUser.LiebUserId, liebUser.GuildWars2Accounts.FirstOrDefault().GuildWars2AccountId, role.PlannedRaidRoleId, SignUpType.Backup);
|
||||
}
|
||||
_raid = RaidService.GetRaid(_raid.RaidId);
|
||||
}
|
||||
|
||||
async Task MaybeClicked(PlannedRaidRole role, LiebUser liebUser, bool isSignedUp)
|
||||
{
|
||||
if(isSignedUp)
|
||||
{
|
||||
await RaidService.ChangeSignUpType(_raid.RaidId, liebUser.LiebUserId, role.PlannedRaidRoleId, SignUpType.Maybe);
|
||||
}
|
||||
else
|
||||
{
|
||||
await RaidService.SignUp(_raid.RaidId, liebUser.LiebUserId, liebUser.GuildWars2Accounts.FirstOrDefault().GuildWars2AccountId, role.PlannedRaidRoleId, SignUpType.Maybe);
|
||||
await RaidService.SignUp(_raid.RaidId, liebUser.LiebUserId, liebUser.GuildWars2Accounts.FirstOrDefault().GuildWars2AccountId, role.PlannedRaidRoleId, signUpType);
|
||||
}
|
||||
_raid = RaidService.GetRaid(_raid.RaidId);
|
||||
}
|
||||
|
|
|
@ -1,6 +1,11 @@
|
|||
@page "/raidoverview"
|
||||
@using Lieb.Data
|
||||
@using System.Security.Claims
|
||||
@using Lieb.Models
|
||||
@using Lieb.Models.GuildWars2.Raid
|
||||
@inject RaidService RaidService
|
||||
@inject UserService UserService
|
||||
@inject AuthenticationStateProvider AuthenticationStateProvider
|
||||
|
||||
|
||||
<h3>RaidOverview</h3>
|
||||
|
@ -15,19 +20,28 @@
|
|||
</AuthorizeView>
|
||||
|
||||
|
||||
@foreach (var raid in raids) {
|
||||
@foreach (var raid in _raids) {
|
||||
<br />
|
||||
<RaidDetails _raid=@raid />
|
||||
<RaidDetails _raid=@raid _user=@_user/>
|
||||
}
|
||||
|
||||
|
||||
|
||||
@code
|
||||
{
|
||||
private List<Models.GuildWars2.Raid.Raid> raids;
|
||||
private List<Raid> _raids;
|
||||
private LiebUser? _user;
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
raids = RaidService.GetRaids();
|
||||
var authState = await AuthenticationStateProvider.GetAuthenticationStateAsync();
|
||||
|
||||
if (authState.User.Identity.IsAuthenticated)
|
||||
{
|
||||
ulong discordId = ulong.Parse(authState.User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.NameIdentifier).Value);
|
||||
_user = UserService.GetLiebUserSmall(discordId);
|
||||
}
|
||||
|
||||
_raids = RaidService.GetRaids();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue