Edits Global/GlobalEntity.cs and adds a test Create
This commit is contained in:
0
WatchLog/Components/Pages/Component.razor
Normal file
0
WatchLog/Components/Pages/Component.razor
Normal file
38
WatchLog/Components/Pages/GlobalEntities.razor
Normal file
38
WatchLog/Components/Pages/GlobalEntities.razor
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
@rendermode InteractiveServer
|
||||||
|
@page "/"
|
||||||
|
@using Microsoft.EntityFrameworkCore
|
||||||
|
@using WatchLog.Data
|
||||||
|
@inject IDbContextFactory<WatchLogDataContext> WatchLogDataContextFactory;
|
||||||
|
<PageTitle>GlobalEntities</PageTitle>
|
||||||
|
|
||||||
|
@if (ShowCreate)
|
||||||
|
{
|
||||||
|
<h3>Add a New GlobalEntity</h3>
|
||||||
|
<div class="row">
|
||||||
|
<label for="Title" class="col-4 col-form-label">Name</label>
|
||||||
|
<div class="col-8">
|
||||||
|
<input id="Title" name="Title" type="text" class="form-control" @bind="@NewGlobalEntity.Title" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="row">
|
||||||
|
<label for="Password" class="col-4 col-form-label">Password</label>
|
||||||
|
<div class="col-8">
|
||||||
|
<input id="Password" name="Password" type="text" class="form-control"/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="form-group row">
|
||||||
|
<div class="offset-4 col-8">
|
||||||
|
<button name="submit" type="submit" class="btn btn-primary" @onclick="CreateNewGlobalEntity">Submit</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
<div class="form-group row">
|
||||||
|
<div class="offset-4 col-8">
|
||||||
|
<button name="submit" type="submit" class="btn btn-primary" @onclick="ShowCreateForm">Add a new Global Entity</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<p>SHOW THE LIST</p>
|
||||||
|
}
|
||||||
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -23,10 +23,10 @@ namespace WatchLog.Data
|
|||||||
|
|
||||||
// --- Foreign Keys ---
|
// --- Foreign Keys ---
|
||||||
[Required]
|
[Required]
|
||||||
public int TypeId { get; set; }
|
public required int TypeId { get; set; }
|
||||||
|
|
||||||
[Required]
|
[Required]
|
||||||
public int CreatorId { get; set; }
|
public required int CreatorId { get; set; }
|
||||||
|
|
||||||
|
|
||||||
// --- Navigation Properties ---
|
// --- Navigation Properties ---
|
||||||
|
|||||||
Reference in New Issue
Block a user