mirror of
https://github.com/aaru-dps/Aaru.Server.git
synced 2025-12-16 11:14:27 +00:00
Add edit view for FireWire devices with form validation
This commit is contained in:
44
Aaru.Server/Components/Admin/Pages/FireWire/Edit.razor
Normal file
44
Aaru.Server/Components/Admin/Pages/FireWire/Edit.razor
Normal 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>
|
||||
}
|
||||
37
Aaru.Server/Components/Admin/Pages/FireWire/Edit.razor.cs
Normal file
37
Aaru.Server/Components/Admin/Pages/FireWire/Edit.razor.cs
Normal 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");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user