@page "/Profile/Saves"
@using Microsoft.AspNetCore.Components.Authorization;
@using Microsoft.EntityFrameworkCore;
@inject UserService UserService
@inject GameSaveService GameSaveService
@inject AuthenticationStateProvider AuthenticationStateProvider
@inject IJSRuntime JSRuntime
@attribute [Authorize]
@code {
DataTable Table;
User User = new User();
ICollection GameSaves = new List();
IEnumerable Games = new List();
bool Loading = true;
Guid GameId = Guid.Empty;
protected override async Task OnInitializedAsync()
{
await LoadData();
}
async Task LoadData() {
Loading = true;
var authState = await AuthenticationStateProvider.GetAuthenticationStateAsync();
if (authState.User.Identity.IsAuthenticated)
User = await UserService
.GetAsync(authState.User.Identity.Name);
GameSaves = (await GameSaveService
.Query(q =>
{
return q
.Include(gs => gs.Game)
.ThenInclude(g => g.Media);
})
.SortBy(gs => gs.Game.Title)
.GetAsync(gs => gs.UserId == User.Id)).OrderByDescending(gs => gs.UpdatedOn).ToList();
if (GameSaves != null && GameSaves.Count > 0)
Games = GameSaves.Where(gs => gs.Game != null).Select(gs => gs.Game).DistinctBy(g => g.Id).ToList();
Loading = false;
}
async Task Download(Guid id)
{
await JSRuntime.InvokeAsync