Files
CouchLog/WatchLog/Components/Pages/GlobalEntities.razor.cs
2025-04-25 22:33:35 +02:00

46 lines
1.1 KiB
C#

using Microsoft.AspNetCore.Components;
using WatchLog.Data;
namespace WatchLog.Components.Pages
{
public partial class GlobalEntities
{
public bool ShowCreate { get; set; }
private WatchLogDataContext? _context;
public required GlobalEntity NewGlobalEntity { get; set; }
protected override Task OnInitializedAsync()
{
ShowCreate = false;
return Task.CompletedTask;
}
public void ShowCreateForm()
{
ShowCreate = true;
NewGlobalEntity = new GlobalEntity
{
Title = "",
CreationTime = DateTime.Now,
CreatorId = 1,
TypeId = 1,
};
}
public async Task CreateNewGlobalEntity()
{
_context ??= await WatchLogDataContextFactory.CreateDbContextAsync();
if (NewGlobalEntity is not null)
{
_context?.GlobalEntities.Add(NewGlobalEntity);
_context?.SaveChangesAsync();
}
ShowCreate = false;
}
}
}