diff --git a/Server/src/SOR.Admin/Components/Pages/Accounts/AccountDetail.razor b/Server/src/SOR.Admin/Components/Pages/Accounts/AccountDetail.razor index b987e62..8c891f8 100644 --- a/Server/src/SOR.Admin/Components/Pages/Accounts/AccountDetail.razor +++ b/Server/src/SOR.Admin/Components/Pages/Accounts/AccountDetail.razor @@ -235,6 +235,92 @@ else + + +
+
+
+ Account Properties @_props.Count + snake_case keys · string values +
+
+ @if (_props.Count > 0) + { + + + + + + + + + + + @foreach (var prop in _props.OrderBy(p => p.Key)) + { + var p = prop; + + + + + + + } + +
KeyValueUpdated
@p.Key + @if (_editingPropId == p.Id) + { + + } + else + { + @p.Value + } + @p.UpdatedAt.ToString("yyyy-MM-dd HH:mm") + @if (_editingPropId == p.Id) + { + + + } + else + { + + + } +
+ } + else + { +

No properties set.

+ } + + +
+
+ + +
+
+ + +
+ +
+
+
+
} @@ -256,6 +342,13 @@ else private string _newDisplayName = ""; private bool _forceLoggingOut; + // Account properties + private List _props = new(); + private Guid _editingPropId = Guid.Empty; + private string _editPropValue = ""; + private string _newPropKey = ""; + private string _newPropValue = ""; + protected override async Task OnInitializedAsync() { _account = await UserManager.FindByIdAsync(Id.ToString()); @@ -263,6 +356,10 @@ else { _roles = (await UserManager.GetRolesAsync(_account)).ToList(); RefreshStatus(); + _props = await Db.AccountProperties + .Where(p => p.AccountId == _account.Id) + .OrderBy(p => p.Key) + .ToListAsync(); } } @@ -432,4 +529,73 @@ else _forceLoggingOut = false; } } + + // ── Account Properties ───────────────────────────────────────────────────── + + private void StartEditProp(AccountProperty prop) + { + _editingPropId = prop.Id; + _editPropValue = prop.Value; + } + + private void CancelEditProp() + { + _editingPropId = Guid.Empty; + _editPropValue = ""; + } + + private async Task SavePropAsync(AccountProperty prop) + { + prop.Value = _editPropValue; + prop.UpdatedAt = DateTimeOffset.UtcNow; + await Db.SaveChangesAsync(); + CancelEditProp(); + _message = $"Property \"{prop.Key}\" updated."; + _isError = false; + } + + private async Task DeletePropAsync(AccountProperty prop) + { + Db.AccountProperties.Remove(prop); + await Db.SaveChangesAsync(); + _props.Remove(prop); + _message = $"Property \"{prop.Key}\" deleted."; + _isError = false; + } + + private async Task AddPropAsync() + { + if (_account == null) return; + var key = _newPropKey.Trim().ToLowerInvariant(); + if (string.IsNullOrEmpty(key)) + { + _message = "Key cannot be empty."; + _isError = true; + return; + } + if (_props.Any(p => p.Key == key)) + { + _message = $"Property \"{key}\" already exists — edit it in the table."; + _isError = true; + return; + } + + var now = DateTimeOffset.UtcNow; + var prop = new AccountProperty + { + Id = Guid.NewGuid(), + AccountId = _account.Id, + Key = key, + Value = _newPropValue.Trim(), + CreatedAt = now, + UpdatedAt = now, + }; + Db.AccountProperties.Add(prop); + await Db.SaveChangesAsync(); + _props.Add(prop); + _newPropKey = ""; + _newPropValue = ""; + _message = $"Property \"{key}\" added."; + _isError = false; + } }