Made Create GlobalEntity to function and added MudCard for GlobalEntitys

This commit is contained in:
2026-03-24 00:00:55 +01:00
parent 2e9ea45bd9
commit 352a7dbfde
5 changed files with 64 additions and 5 deletions
@@ -276,4 +276,4 @@
_isSaving = false;
}
}
}
}
@@ -7,17 +7,18 @@
@using Microsoft.EntityFrameworkCore
@using CouchLog.Components.Pages.GlobalList.Dialogs
@inject ApplicationDbContext CouchLogDB
@inject ApplicationDbContext CouchLogDb
@inject UserManager<ApplicationUser> UserManager
@inject AuthenticationStateProvider AuthenticationStateProvider
@inject NavigationManager NavigationManager
@inject IDialogService DialogService
@inject ISnackbar Snackbar
@attribute [Authorize]
<PageTitle>GlobalList</PageTitle>
<MudContainer>
<MudContainer MaxWidth="MaxWidth.False">
@*Top of the Page*@
<MudContainer>
<MudStack Row="true" AlignItems="AlignItems.Center">
@@ -33,13 +34,67 @@
</MudTooltip>
</MudStack>
</MudContainer>
<br/>
<MudContainer MaxWidth="MaxWidth.False">
<MudGrid Spacing="6" Justify="Justify.Center">
@foreach (var entity in _globalEntities)
{
if (!entity.IsPrivate || (entity.IsPrivate && (entity.CreatorId == _appUser?.Id)))
{
<MudItem xs="12" sm="6" md="4" lg="2">
<MudCard>
<MudCardMedia Image="@entity.PicturePath" />
<MudCardContent>
<MudText Typo="Typo.h5">@entity.Title</MudText>
</MudCardContent>
<MudCardActions>
<MudTooltip Text="Add to shared List">
<MudIconButton Icon="@Icons.Material.Rounded.People" Color="Color.Primary" OnClick="AddGlobalEntityToSharedList"/>
</MudTooltip>
<MudTooltip Text="Add to private List">
<MudIconButton Icon="@Icons.Material.Rounded.Lock" Color="Color.Primary" />
</MudTooltip>
</MudCardActions>
</MudCard>
</MudItem>
}
}
</MudGrid>
</MudContainer>
</MudContainer>
@code
{
private ApplicationUser? _appUser;
private List<GlobalEntity> _globalEntities = [];
private HashSet<int> _userPrivateEntityIds = [];
protected override async Task OnInitializedAsync()
{
_globalEntities = await CouchLogDb.GlobalEntities.OrderByDescending(entity => entity.CreationTime).ToListAsync();
var authState = await AuthenticationStateProvider.GetAuthenticationStateAsync();
_appUser = await UserManager.GetUserAsync(authState.User);
if (_appUser is null)
{
Snackbar.Add("Not authenticated.", Severity.Error);
return;
}
_userPrivateEntityIds = await CouchLogDb.PrivateEntities
.Where(entity => entity.UserId == _appUser.Id)
.Select(p => p.GlobalEntityId)
.ToHashSetAsync();
}
private async Task OpenAddNewGlobalEntityDialog()
{
var dialog = await DialogService.ShowAsync<AddNewGlobalEntityDialog>("Add new Global Entity");
}
private async Task AddGlobalEntityToSharedList()
{
Snackbar.Add("Feature not implemented yet!", Severity.Error);
}
}
+5 -1
View File
@@ -5,6 +5,7 @@ using CouchLog.Components;
using CouchLog.Components.Account;
using CouchLog.Data;
using CouchLog;
using MudBlazor;
using MudBlazor.Services;
var builder = WebApplication.CreateBuilder(args);
@@ -36,7 +37,10 @@ builder.Services.AddIdentityCore<ApplicationUser>(options => options.SignIn.Requ
.AddDefaultTokenProviders();
builder.Services.AddSingleton<IEmailSender<ApplicationUser>, IdentityNoOpEmailSender>();
builder.Services.AddMudServices();
builder.Services.AddMudServices(config =>
{
config.SnackbarConfiguration.PositionClass = Defaults.Classes.Position.BottomCenter;
});
var app = builder.Build();