Fix: Correct the submission of new school subjects
All checks were successful
SonarQube Scan / SonarQube Trigger (push) Successful in 36s

This commit is contained in:
Namu
2025-12-20 21:46:44 +01:00
parent e1341bd0a1
commit 85fbc5eb19
6 changed files with 343 additions and 22 deletions

View File

@@ -1,48 +1,53 @@
@page "/school-subjects/creation"
@rendermode InteractiveServer
@attribute [Authorize]
@using Microsoft.AspNetCore.Authorization
@using WorkManagementTool.Services
@using WorkManagementTool.Data.Entities;
@inject SchoolSubjectService SchoolSubjectService
@inject NavigationManager NavigationManager
@inject ILogger<SchoolSubjectCreation> Logger
<h3>SchoolSubjectCreation</h3>
<EditForm Model="@Model" OnValidSubmit="Submit" FormName="school-subject-creation">
@if (!string.IsNullOrEmpty(errorMessage))
{
<div class="alert alert-danger">@errorMessage</div>
}
<EditForm Model="@Model"
OnValidSubmit="Submit"
FormName="school-subject-creation">
<ValidationSummary />
<DataAnnotationsValidator />
<div class="form-group">
<label for="name" class="form-label">Name</label>
<InputText class="form-control" @bind-value="Model!.Name" />
<InputText id="name" class="form-control" @bind-Value="Model!.Name" />
<ValidationMessage For="@(() => Model!.Name)" />
</div>
<div class="form-group">
<label for="description" class="form-label">Description</label>
<InputTextArea class="form-control" @bind-value="Model!.Description"></InputTextArea>
<InputTextArea id="description" class="form-control" @bind-Value="Model!.Description"></InputTextArea>
<ValidationMessage For="@(() => Model!.Description)" />
</div>
<button type="submit" class="btn btn-primary">Create School Subject</button>
</EditForm>
@code {
[SupplyParameterFromForm]
private SchoolSubject? Model { get; set; }
private SchoolSubject Model { get; set; } = new();
protected override void OnInitialized()
{
if (Model is null)
{
Model = new SchoolSubject
{
Name = null!,
Description = null,
};
}
}
private string? errorMessage;
private async Task Submit()
{
await SchoolSubjectService.AddSchoolSubjectAsync(Model!);
NavigationManager.NavigateTo("/school-subjects");
if (Model is not null)
{
await SchoolSubjectService.AddSchoolSubjectAsync(Model);
Logger.LogInformation("SchoolSubject created: {Name}", Model.Name);
NavigationManager.NavigateTo("/school-subjects");
}
}
}
}