LANCommander/LANCommander.Server/UI/Pages/Settings/Tools/ActiveSessions.razor

78 lines
2.6 KiB
Text

@page "/Settings/Tools/ActiveSessions"
@using LANCommander.Server.Models;
@using LANCommander.Server.UI.Pages.Games.Components;
@using Microsoft.EntityFrameworkCore
@inject DatabaseServiceFactory DatabaseServiceFactory
@inject IMessageService MessageService
@inject ILogger<ActiveSessions> Logger
@attribute [Authorize(Roles = RoleService.AdministratorRoleName)]
<PageHeader Title="Active Sessions" />
<div style="padding: 0 24px;">
<p>
These play sessions are considered active because they never ended. This may cause servers set to autostart with "Player Activity" to not stop when a player has quit a game.
</p>
<Table TItem="PlaySession" DataSource="@PlaySessions" Loading="@Loading" Responsive>
<PropertyColumn Property="ps => ps.Game.Title" Title="Game" />
<PropertyColumn Property="ps => ps.Start" />
<PropertyColumn Property="ps => ps.End" />
<PropertyColumn Property="ps => ps.CreatedOn" Format="MM/dd/yyyy hh:mm tt" Sortable DefaultSortOrder="@SortDirection.Descending" />
<PropertyColumn Property="ps => ps.CreatedBy" Sortable>
@context.CreatedBy?.UserName
</PropertyColumn>
<ActionColumn Title="" Style="text-align: right">
<Space Direction="DirectionVHType.Horizontal">
<SpaceItem>
<Popconfirm OnConfirm="() => Delete(context)" Title="Are you sure you want to delete this session?">
<Button Icon="@IconType.Outline.Close" Type="@ButtonType.Text" Danger />
</Popconfirm>
</SpaceItem>
</Space>
</ActionColumn>
</Table>
</div>
@code {
ICollection<PlaySession> PlaySessions;
bool Loading = true;
protected override async Task OnInitializedAsync()
{
await LoadData();
}
async Task LoadData()
{
Loading = true;
using (var playSessionService = DatabaseServiceFactory.Create<PlaySessionService>())
{
PlaySessions = await playSessionService.GetAsync(ps => !ps.End.HasValue);
}
Loading = false;
}
async Task Delete(PlaySession playSession)
{
try
{
using (var playSessionService = DatabaseServiceFactory.Create<PlaySessionService>())
{
await playSessionService.DeleteAsync(playSession);
}
await LoadData();
MessageService.Success("Session deleted!");
}
catch (Exception ex)
{
MessageService.Error("Session could not be deleted.");
Logger.LogError(ex, "Session could not be deleted.");
}
}
}