@using RackPeek.Domain.Resources.OtherHardware @inject UpdateOtherUseCase UpdateUseCase @inject IGetResourceByNameUseCase GetByNameUseCase @inject IDeleteResourceUseCase DeleteUseCase @inject IRenameResourceUseCase RenameUseCase @inject ICloneResourceUseCase CloneUseCase @inject NavigationManager Nav
@Other.Name
@if (!_isEditing) { } else { }
Model
@if (_isEditing) { } else if (!string.IsNullOrWhiteSpace(Other.Model)) {
@Other.Model
}
Description
@if (_isEditing) { } else if (!string.IsNullOrWhiteSpace(Other.Description)) {
@Other.Description
}
Notes
@if (_isEditing) { } else { }
Are you sure you want to delete @Other.Name? @code { [Parameter] [EditorRequired] public Other Other { get; set; } = default!; [Parameter] public EventCallback OnDeleted { get; set; } bool _isEditing; bool _confirmDeleteOpen; OtherEditModel _edit = new(); void BeginEdit() { _edit = OtherEditModel.From(Other); _isEditing = true; } async Task Save() { _isEditing = false; await UpdateUseCase.ExecuteAsync( Other.Name, _edit.Model, _edit.Description, _edit.Notes); Other = await GetByNameUseCase.ExecuteAsync(Other.Name); } void Cancel() { _isEditing = false; } void ConfirmDelete() { _confirmDeleteOpen = true; } async Task DeleteOther() { _confirmDeleteOpen = false; await DeleteUseCase.ExecuteAsync(Other.Name); if (OnDeleted.HasDelegate) await OnDeleted.InvokeAsync(Other.Name); } bool _renameOpen; void OpenRename() { _renameOpen = true; } async Task HandleRenameSubmit(string newName) { await RenameUseCase.ExecuteAsync(Other.Name, newName); Nav.NavigateTo($"resources/hardware/{Uri.EscapeDataString(newName)}"); } bool _cloneOpen; void OpenClone() { _cloneOpen = true; } async Task HandleCloneSubmit(string newName) { await CloneUseCase.ExecuteAsync(Other.Name, newName); Nav.NavigateTo($"resources/hardware/{Uri.EscapeDataString(newName)}"); } public class OtherEditModel { public string? Model { get; set; } public string? Description { get; set; } public string? Notes { get; set; } public static OtherEditModel From(Other other) { return new OtherEditModel { Model = other.Model, Description = other.Description, Notes = other.Notes }; } } }