mirror of
https://github.com/aaru-dps/Aaru.Server.git
synced 2025-12-16 11:14:27 +00:00
Add edit view for tested media with form validation
This commit is contained in:
53
Aaru.Server/Components/Admin/Pages/TestedMedia/Edit.razor
Normal file
53
Aaru.Server/Components/Admin/Pages/TestedMedia/Edit.razor
Normal file
@@ -0,0 +1,53 @@
|
||||
@page "/admin/tested-media/edit/{Id:int}"
|
||||
@attribute [Authorize]
|
||||
@layout AdminLayout
|
||||
|
||||
<PageTitle>Edit Tested Media</PageTitle>
|
||||
|
||||
@if(!isLoaded)
|
||||
{
|
||||
<div>Loading...</div>
|
||||
}
|
||||
else
|
||||
{
|
||||
<EditForm Model="testedMedia" OnValidSubmit="HandleValidSubmit">
|
||||
<DataAnnotationsValidator />
|
||||
<ValidationSummary />
|
||||
<div class="mb-3">
|
||||
<label class="form-label">Manufacturer</label>
|
||||
<InputText class="form-control" @bind-Value="testedMedia.Manufacturer" />
|
||||
<ValidationMessage For="@(() => testedMedia.Manufacturer)" />
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label class="form-label">Model</label>
|
||||
<InputText class="form-control" @bind-Value="testedMedia.Model" />
|
||||
<ValidationMessage For="@(() => testedMedia.Model)" />
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label class="form-label">Medium Type Name</label>
|
||||
<InputText class="form-control" @bind-Value="testedMedia.MediumTypeName" />
|
||||
<ValidationMessage For="@(() => testedMedia.MediumTypeName)" />
|
||||
</div>
|
||||
<div class="mb-3 form-check">
|
||||
<InputCheckbox class="form-check-input" @bind-Value="testedMedia.MediaIsRecognized" />
|
||||
<label class="form-check-label">Media Is Recognized</label>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label class="form-label">Blocks</label>
|
||||
<InputNumber class="form-control" @bind-Value="testedMedia.Blocks" />
|
||||
<ValidationMessage For="@(() => testedMedia.Blocks)" />
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label class="form-label">Block Size</label>
|
||||
<InputNumber class="form-control" @bind-Value="testedMedia.BlockSize" />
|
||||
<ValidationMessage For="@(() => testedMedia.BlockSize)" />
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label class="form-label">Long Block Size</label>
|
||||
<InputNumber class="form-control" @bind-Value="testedMedia.LongBlockSize" />
|
||||
<ValidationMessage For="@(() => testedMedia.LongBlockSize)" />
|
||||
</div>
|
||||
<button type="submit" class="btn btn-primary">Save</button>
|
||||
<button type="button" class="btn btn-secondary ms-2" @onclick="GoBack">Cancel</button>
|
||||
</EditForm>
|
||||
}
|
||||
86
Aaru.Server/Components/Admin/Pages/TestedMedia/Edit.razor.cs
Normal file
86
Aaru.Server/Components/Admin/Pages/TestedMedia/Edit.razor.cs
Normal file
@@ -0,0 +1,86 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using Microsoft.AspNetCore.Components;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using DbContext = Aaru.Server.Database.DbContext;
|
||||
|
||||
namespace Aaru.Server.Components.Admin.Pages.TestedMedia;
|
||||
|
||||
public partial class Edit : ComponentBase
|
||||
{
|
||||
DbContext db;
|
||||
bool isLoaded;
|
||||
|
||||
TestedMediaViewModel testedMedia = new();
|
||||
[Parameter]
|
||||
public int Id { get; set; }
|
||||
|
||||
[Inject]
|
||||
public IDbContextFactory<DbContext> DbContextFactory { get; set; }
|
||||
|
||||
[Inject]
|
||||
public NavigationManager Navigation { get; set; }
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
db = await DbContextFactory.CreateDbContextAsync();
|
||||
CommonTypes.Metadata.TestedMedia? entity = await db.TestedMedia.FindAsync(Id);
|
||||
|
||||
if(entity != null)
|
||||
{
|
||||
testedMedia = new TestedMediaViewModel
|
||||
{
|
||||
Id = Id,
|
||||
Manufacturer = entity.Manufacturer,
|
||||
Model = entity.Model,
|
||||
MediumTypeName = entity.MediumTypeName,
|
||||
MediaIsRecognized = entity.MediaIsRecognized,
|
||||
Blocks = entity.Blocks,
|
||||
BlockSize = entity.BlockSize,
|
||||
LongBlockSize = entity.LongBlockSize
|
||||
};
|
||||
}
|
||||
|
||||
isLoaded = true;
|
||||
}
|
||||
|
||||
protected async Task HandleValidSubmit()
|
||||
{
|
||||
CommonTypes.Metadata.TestedMedia? entity = await db.TestedMedia.FindAsync(Id);
|
||||
|
||||
if(entity != null)
|
||||
{
|
||||
entity.Manufacturer = testedMedia.Manufacturer;
|
||||
entity.Model = testedMedia.Model;
|
||||
entity.MediumTypeName = testedMedia.MediumTypeName;
|
||||
entity.MediaIsRecognized = testedMedia.MediaIsRecognized;
|
||||
entity.Blocks = testedMedia.Blocks;
|
||||
entity.BlockSize = testedMedia.BlockSize;
|
||||
entity.LongBlockSize = testedMedia.LongBlockSize;
|
||||
await db.SaveChangesAsync();
|
||||
}
|
||||
|
||||
Navigation.NavigateTo("/admin/tested-media");
|
||||
}
|
||||
|
||||
protected void GoBack()
|
||||
{
|
||||
Navigation.NavigateTo("/admin/tested-media");
|
||||
}
|
||||
|
||||
public class TestedMediaViewModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
[Required]
|
||||
public string Manufacturer { get; set; }
|
||||
[Required]
|
||||
public string Model { get; set; }
|
||||
public string MediumTypeName { get; set; }
|
||||
public bool MediaIsRecognized { get; set; }
|
||||
[Range(0, long.MaxValue)]
|
||||
public ulong? Blocks { get; set; }
|
||||
[Range(0, int.MaxValue)]
|
||||
public uint? BlockSize { get; set; }
|
||||
[Range(0, int.MaxValue)]
|
||||
public uint? LongBlockSize { get; set; }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user