Add edit view for FireWire devices with form validation

This commit is contained in:
2025-09-12 16:51:10 +01:00
parent 45b6551b40
commit 1c3ecd731e
2 changed files with 81 additions and 0 deletions

View File

@@ -0,0 +1,44 @@
@page "/admin/firewire/edit/{Id:int}"
@attribute [Authorize]
@layout AdminLayout
@inject Microsoft.EntityFrameworkCore.IDbContextFactory<DbContext> DbContextFactory
<PageTitle>Edit FireWire Device</PageTitle>
@if(!_isLoaded)
{
<div>Loading...</div>
}
else
{
<EditForm Model="_fireWire" OnValidSubmit="HandleValidSubmit">
<DataAnnotationsValidator />
<ValidationSummary />
<div class="mb-3">
<label class="form-label">Vendor ID</label>
<InputNumber class="form-control" @bind-Value="_fireWire.VendorID" />
<ValidationMessage For="@(() => _fireWire.VendorID)" />
</div>
<div class="mb-3">
<label class="form-label">Product ID</label>
<InputNumber class="form-control" @bind-Value="_fireWire.ProductID" />
<ValidationMessage For="@(() => _fireWire.ProductID)" />
</div>
<div class="mb-3">
<label class="form-label">Manufacturer</label>
<InputText class="form-control" @bind-Value="_fireWire.Manufacturer" />
<ValidationMessage For="@(() => _fireWire.Manufacturer)" />
</div>
<div class="mb-3">
<label class="form-label">Product</label>
<InputText class="form-control" @bind-Value="_fireWire.Product" />
<ValidationMessage For="@(() => _fireWire.Product)" />
</div>
<div class="mb-3 form-check">
<InputCheckbox class="form-check-input" @bind-Value="_fireWire.RemovableMedia" />
<label class="form-check-label">Is media removable?</label>
</div>
<button type="submit" class="btn btn-primary">Save</button>
<button type="button" class="btn btn-secondary ms-2" @onclick="GoBack">Cancel</button>
</EditForm>
}

View File

@@ -0,0 +1,37 @@
using Microsoft.AspNetCore.Components;
using DbContext = Aaru.Server.Database.DbContext;
namespace Aaru.Server.Components.Admin.Pages.FireWire;
public partial class Edit : ComponentBase
{
DbContext _db;
CommonTypes.Metadata.FireWire _fireWire = new();
bool _isLoaded;
[Parameter]
public int Id { get; set; }
[Inject]
public NavigationManager Navigation { get; set; }
protected override async Task OnInitializedAsync()
{
_db = await DbContextFactory.CreateDbContextAsync();
CommonTypes.Metadata.FireWire? entity = await _db.FireWire.FindAsync(Id);
if(entity != null) _fireWire = entity;
_isLoaded = true;
}
async Task HandleValidSubmit()
{
_db.Update(_fireWire);
await _db.SaveChangesAsync();
Navigation.NavigateTo("/admin/firewire");
}
void GoBack()
{
Navigation.NavigateTo("/admin/firewire");
}
}