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; } } }