Fix: Correct the submission of new school subjects
All checks were successful
SonarQube Scan / SonarQube Trigger (push) Successful in 36s
All checks were successful
SonarQube Scan / SonarQube Trigger (push) Successful in 36s
This commit is contained in:
@@ -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");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user