diff --git a/WatchLog/Components/Pages/Component.razor b/WatchLog/Components/Pages/Component.razor new file mode 100644 index 0000000..e69de29 diff --git a/WatchLog/Components/Pages/GlobalEntities.razor b/WatchLog/Components/Pages/GlobalEntities.razor new file mode 100644 index 0000000..c059e87 --- /dev/null +++ b/WatchLog/Components/Pages/GlobalEntities.razor @@ -0,0 +1,38 @@ +@rendermode InteractiveServer +@page "/" +@using Microsoft.EntityFrameworkCore +@using WatchLog.Data +@inject IDbContextFactory WatchLogDataContextFactory; +GlobalEntities + +@if (ShowCreate) +{ +

Add a New GlobalEntity

+
+ +
+ +
+
+
+ +
+ +
+
+
+
+ +
+
+} +else +{ +
+
+ +
+
+ +

SHOW THE LIST

+} \ No newline at end of file diff --git a/WatchLog/Components/Pages/GlobalEntities.razor.cs b/WatchLog/Components/Pages/GlobalEntities.razor.cs new file mode 100644 index 0000000..ec5d39e --- /dev/null +++ b/WatchLog/Components/Pages/GlobalEntities.razor.cs @@ -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; + } + } +} diff --git a/WatchLog/Data/Database/Global/GlobalEntity.cs b/WatchLog/Data/Database/Global/GlobalEntity.cs index b3babc4..90efcd7 100644 --- a/WatchLog/Data/Database/Global/GlobalEntity.cs +++ b/WatchLog/Data/Database/Global/GlobalEntity.cs @@ -23,10 +23,10 @@ namespace WatchLog.Data // --- Foreign Keys --- [Required] - public int TypeId { get; set; } + public required int TypeId { get; set; } [Required] - public int CreatorId { get; set; } + public required int CreatorId { get; set; } // --- Navigation Properties ---