Edits Global/GlobalEntity.cs and adds a test Create

This commit is contained in:
Henry Trumme
2025-04-25 22:33:35 +02:00
parent 1b40ea2cea
commit cca0f6c6a4
4 changed files with 85 additions and 2 deletions

View File

@@ -0,0 +1,45 @@
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;
}
}
}