@page "/PrivateList" @rendermode InteractiveServer @using Microsoft.AspNetCore.Authorization @using CouchLog.Data @using Microsoft.AspNetCore.Identity @using Microsoft.EntityFrameworkCore @inject ApplicationDbContext CouchLogDB @inject UserManager UserManager @inject AuthenticationStateProvider AuthenticationStateProvider @inject NavigationManager NavigationManager @attribute [Authorize] Private List
@if (ActiveWatchingEntities.Any()) {

Aktiv am Schauen

@foreach (var entity in ActiveWatchingEntities) { @RenderEntityCard(entity) }
} @if (LibraryEntities.Any()) {

Bibliothek

@foreach (var entity in LibraryEntities) { @RenderEntityCard(entity) }
} @if (!PrivateEntities.Any()) {

Keine Einträge vorhanden.

}
@code { private List PrivateEntities = new List(); private List userWatchStatuses = new List(); ApplicationUser? AppUser = new(); private List ActiveWatchingEntities => PrivateEntities.Where(x => x.UserWatchStatus?.Name == "Watching").ToList(); private List LibraryEntities => PrivateEntities.Where(x => x.UserWatchStatus?.Name != "Watching").ToList(); protected override async Task OnInitializedAsync() { var AuthState = await AuthenticationStateProvider.GetAuthenticationStateAsync(); AppUser = await UserManager.GetUserAsync(AuthState.User); if (AppUser != null) { PrivateEntities = await CouchLogDB.PrivateEntities .Where(x => x.UserId == AppUser.Id) .Include(x => x.GlobalEntity) .Include(x => x.UserWatchStatus) .Include(x => x.GlobalEntity.MediaType) .OrderByDescending(Entity => Entity.LastChange ?? Entity.CreationTime) .ToListAsync(); userWatchStatuses = await CouchLogDB.UserWatchStatuses.OrderByDescending(Entity => Entity.Id).ToListAsync(); } } private RenderFragment RenderEntityCard(PrivateEntity Entity) => __builder => {
@if (!string.IsNullOrEmpty(Entity.GlobalEntity?.PicturePath)) { @Entity.GlobalEntity.Title } else {
Kein Bild
}
@Entity.GlobalEntity?.Title
@Entity.CreationTime.ToShortDateString()
@if (Entity.GlobalEntity?.MediaType.Name == "Series" || Entity.GlobalEntity?.MediaType.Name == "Anime") { }
}; private async Task RemoveEntityFromPrivateList(PrivateEntity entity) { //Delete DB CouchLogDB.PrivateEntities.Remove(entity); await CouchLogDB.SaveChangesAsync(); //Delete Memory List PrivateEntities.Remove(entity); } private async Task UpdateWatchStatus(PrivateEntity entity, object? newValue) { if (int.TryParse(newValue?.ToString(), out int newId)) { entity.UserWatchStatusId = newId; entity.UserWatchStatus = userWatchStatuses.FirstOrDefault(s => s.Id == newId); await CouchLogDB.SaveChangesAsync(); } } private async Task UpdateSeason(PrivateEntity entity, object? newSeasonValue) { if (int.TryParse(newSeasonValue?.ToString(), out int newSeason)) { entity.Season = newSeason; entity.Episode = 1; await CouchLogDB.SaveChangesAsync(); } } private async Task UpdateEpisode(PrivateEntity entity, object? newEpisodeValue) { if (int.TryParse(newEpisodeValue?.ToString(), out int newEpisode)) { entity.Episode = newEpisode; await CouchLogDB.SaveChangesAsync(); } } }