Lieb-Website/Lieb/Pages/Raids/RaidDetails.razor
2022-03-12 21:55:11 +01:00

130 lines
3.6 KiB
Text

@using System.Security.Claims
@using Lieb.Data
@using Lieb.Models
@using Lieb.Models.GuildWars2.Raid
@inject UserService UserService
@inject RaidService RaidService
@inject TimeZoneService TimeZoneService
@inject RaidRandomizerService RaidRandomizerService
<body>
<label>@_errorMessage</label>
<h5>@_raid.Title</h5>
<div>@_raid.Description</div>
<div >
<div class="times">
<h5>Date</h5>
<p>@_startTime.DateTime.ToLongDateString()</p>
</div>
<div class="times">
<h5>Time</h5>
<p>from: @_startTime.LocalDateTime.ToShortTimeString() to: @_endTime.LocalDateTime.ToShortTimeString()</p>
</div>
</div>
<div>
<div class="details">
<h5>Organizer</h5>
<p>@_raid.Organizer</p>
</div>
<div class="details">
<h5>Guild</h5>
<p>@_raid.Guild</p>
</div>
<div class="details">
<h5>Voice chat</h5>
<p>@_raid.VoiceChat</p>
</div>
</div>
@if(_isRaidSignUpAllowed)
{
if(_raid.RaidType == RaidType.Planned)
{
<RaidRolesPlanned _raid=@_raid _user=@_user/>
}
else
{
<RaidRolesPlanned _raid=@_raid _user=@_user/>
}
}
else
{
<RaidRolesNoSignUp _raid=@_raid/>
}
<AuthorizeView Policy="@Constants.Roles.RaidLead">
<div class="nav-item px-3">
@{string navLink = $"raidedit/{_raid.RaidId}";}
<NavLink class="nav-link" href="@navLink">
<span class="oi oi-plus" aria-hidden="true"></span> Edit
</NavLink>
</div>
@if(_raid.RaidType != RaidType.Planned && !_raid.IsRandomized)
{
<button type=button @onclick="() => RandomizeClicked()">Randomize</button>
}
</AuthorizeView>
</body>
@code {
[Parameter]
public Raid _raid { get; set; }
[Parameter]
public LiebUser? _user { get; set; }
bool _isRaidSignUpAllowed;
string _errorMessage;
private DateTimeOffset _startTime;
private DateTimeOffset _endTime;
private DateTimeOffset _freeForAllTime;
protected override async Task OnInitializedAsync()
{
_isRaidSignUpAllowed = _user != null && RaidService.IsRaidSignUpAllowed(_user.LiebUserId, _raid.RaidId, out _errorMessage);
_startTime = await TimeZoneService.GetLocalDateTime(_raid.StartTimeUTC);
_endTime = await TimeZoneService.GetLocalDateTime(_raid.EndTimeUTC);
_freeForAllTime = await TimeZoneService.GetLocalDateTime(_raid.FreeForAllTimeUTC);
}
async Task SignUpClicked(PlannedRaidRole role, LiebUser liebUser, bool isSignedUp, SignUpType signUpType)
{
if(isSignedUp)
{
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);
}
_raid = RaidService.GetRaid(_raid.RaidId);
}
async Task SignOffClicked(PlannedRaidRole role, LiebUser liebUser)
{
await RaidService.SignOff(_raid.RaidId, liebUser.LiebUserId, role.PlannedRaidRoleId);
_raid = RaidService.GetRaid(_raid.RaidId);
}
async Task RandomizeClicked()
{
await RaidRandomizerService.RandomizeRaid(_raid.RaidId);
_raid = RaidService.GetRaid(_raid.RaidId);
}
async Task ChangeAccount(LiebUser liebUser, ChangeEventArgs e)
{
int accountId = int.Parse(e.Value.ToString());
await RaidService.ChangeAccount(_raid.RaidId, liebUser.LiebUserId, accountId);
_raid = RaidService.GetRaid(_raid.RaidId);
}
}