Edits Global/GlobalEntity.cs and adds a test Create
This commit is contained in:
45
WatchLog/Components/Pages/GlobalEntities.razor.cs
Normal file
45
WatchLog/Components/Pages/GlobalEntities.razor.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user