@page "/clusters/new" @attribute [Authorize(Policy = AdminUiPolicies.ConfigEditor)] @rendermode RenderMode.InteractiveServer @using Microsoft.AspNetCore.Components.Forms @using Microsoft.EntityFrameworkCore @using ZB.MOM.WW.OtOpcUa.Configuration @using ZB.MOM.WW.OtOpcUa.Configuration.Entities @using ZB.MOM.WW.OtOpcUa.Configuration.Enums @inject IDbContextFactory DbFactory @inject NavigationManager Nav @inject AuthenticationStateProvider AuthState

New cluster

Cancel
Identity
Topology
NodeCount is implied — 1 for None, 2 for Warm/Hot.
@if (!string.IsNullOrWhiteSpace(_error)) {
@_error
}
Cancel
@code { private FormModel _form = new(); private string? _error; private bool _busy; private async Task SubmitAsync() { _busy = true; _error = null; try { await using var db = await DbFactory.CreateDbContextAsync(); if (await db.ServerClusters.AnyAsync(c => c.ClusterId == _form.ClusterId)) { _error = $"Cluster '{_form.ClusterId}' already exists."; return; } var auth = await AuthState.GetAuthenticationStateAsync(); var createdBy = auth.User.Identity?.Name ?? "(anonymous)"; var entity = new ServerCluster { ClusterId = _form.ClusterId, Name = _form.Name, Enterprise = _form.Enterprise, Site = _form.Site, RedundancyMode = _form.RedundancyMode, NodeCount = _form.RedundancyMode == RedundancyMode.None ? (byte)1 : (byte)2, Notes = string.IsNullOrWhiteSpace(_form.Notes) ? null : _form.Notes, Enabled = true, CreatedAt = DateTime.UtcNow, CreatedBy = createdBy, }; db.ServerClusters.Add(entity); await db.SaveChangesAsync(); Nav.NavigateTo($"/clusters/{entity.ClusterId}"); } catch (Exception ex) { _error = ex.Message; } finally { _busy = false; } } private sealed class FormModel { [System.ComponentModel.DataAnnotations.Required, System.ComponentModel.DataAnnotations.RegularExpression("^[A-Z0-9_-]+$", ErrorMessage = "Use uppercase letters, digits, dash, underscore.")] public string ClusterId { get; set; } = ""; [System.ComponentModel.DataAnnotations.Required] public string Name { get; set; } = ""; [System.ComponentModel.DataAnnotations.Required] public string Enterprise { get; set; } = "zb"; [System.ComponentModel.DataAnnotations.Required] public string Site { get; set; } = ""; public RedundancyMode RedundancyMode { get; set; } = RedundancyMode.None; public string? Notes { get; set; } } }