@page "/Metadata/Collections/{id:guid}" @page "/Metadata/Collections/Add" @using Microsoft.EntityFrameworkCore @attribute [Authorize(Roles = RoleService.AdministratorRoleName)] @inject CollectionService CollectionService @inject IMessageService MessageService @inject NavigationManager NavigationManager @inject ILogger Logger @foreach (var dev in context.Developers ?? []) { @dev.Name } @foreach (var pub in context.Publishers ?? []) { @pub.Name } @foreach (var genre in context.Genres ?? []) { @genre.Name } @foreach (var mode in context.MultiplayerModes?.Select(mm => mm.Type).Distinct() ?? []) { @mode.GetDisplayName() }
@code { [Parameter] public Guid Id { get; set; } Collection Collection = new Collection(); protected override async Task OnInitializedAsync() { if (Id == Guid.Empty) Collection = new Collection(); else Collection = await CollectionService .Query(q => { return q .Include(c => c.Games).ThenInclude(g => g.Media) .Include(c => c.Games).ThenInclude(g => g.Developers) .Include(c => c.Games).ThenInclude(g => g.Publishers) .Include(c => c.Games).ThenInclude(g => g.Genres) .Include(c => c.Games).ThenInclude(g => g.MultiplayerModes) ; }) .AsSplitQuery() .GetAsync(Id); } private async Task Save() { try { if (Collection.Id != Guid.Empty) { Collection = await CollectionService.UpdateAsync(Collection); await MessageService.SuccessAsync("Collection updated!"); } else { Collection = await CollectionService.AddAsync(Collection); NavigationManager.LocationChanged += NotifyCollectionAdded; NavigationManager.NavigateTo($"/Collections/{Collection.Id}"); } } catch (Exception ex) { MessageService.Error("Could not save!"); Logger.LogError(ex, "Could not save!"); } } private void NotifyCollectionAdded(object? sender, LocationChangedEventArgs e) { NavigationManager.LocationChanged -= NotifyCollectionAdded; MessageService.Success("Collection added!"); } private async Task RemoveGame(Game game) { try { Collection.Games.Remove(game); await CollectionService.UpdateAsync(Collection); } catch (Exception ex) { MessageService.Error("Game could not be removed from the collection!"); Logger.LogError(ex, "Game could not be removed from the collection!"); } } private string GetIcon(Game game) { var media = game?.Media?.FirstOrDefault(m => m.Type == SDK.Enums.MediaType.Icon); if (media != null) return $"/api/Media/{media.Id}/Download?fileId={media.FileId}"; else return "/favicon.ico"; } }