From fd8fe950f8ead63882032eca8b961b13f11e3df9 Mon Sep 17 00:00:00 2001 From: dingo Date: Sat, 28 Feb 2026 13:45:37 -0500 Subject: [PATCH] Add Grant Card section to AccountDetail admin page MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Search card definitions by name (ILike, top 20), click a row to select, set quantity (1–99), toggle Tradeable + Foil, then Grant. Creates PlayerCard rows directly in CollectionDbContext. Injects CatalogDbContext + CollectionDbContext (both already registered). Generated with [Claude Code](https://claude.ai/code) via [Happy](https://happy.engineering) Co-Authored-By: Claude Co-Authored-By: Happy --- .../Pages/Accounts/AccountDetail.razor | 172 ++++++++++++++++++ 1 file changed, 172 insertions(+) diff --git a/Server/src/SOR.Admin/Components/Pages/Accounts/AccountDetail.razor b/Server/src/SOR.Admin/Components/Pages/Accounts/AccountDetail.razor index 8c891f8..685b6ec 100644 --- a/Server/src/SOR.Admin/Components/Pages/Accounts/AccountDetail.razor +++ b/Server/src/SOR.Admin/Components/Pages/Accounts/AccountDetail.razor @@ -1,12 +1,15 @@ @page "/accounts/{Id:guid}" @attribute [Authorize(Roles = "Admin,SuperAdmin")] @inject SorIdentityDbContext Db +@inject CatalogDbContext CatalogDb +@inject CollectionDbContext CollectionDb @inject UserManager UserManager @inject NavigationManager Nav @inject IConnectionMultiplexer Redis @using Microsoft.AspNetCore.Identity @using StackExchange.Redis @using SOR.Shared.Redis +@using SOR.Database.Entities.Collection Account – SOR Admin @@ -236,6 +239,107 @@ else + +
+
+
Grant Cards
+
+ +
+ + +
+ + + @if (_grantResults.Count > 0) + { +
+ + + + + + + + + + + @foreach (var def in _grantResults) + { + var d = def; + var isSelected = _selectedDef?.Id == d.Id; + + + + + + + } + +
NameTypeAffinityRarity
@d.Name@d.CardType@d.Affinity@d.Rarity
+
+ } + else if (_grantSearched) + { +

No card definitions found.

+ } + + +
+
+ +
+ @(_selectedDef?.Name ?? "—") +
+
+
+ + +
+
+
+ + +
+
+ + +
+
+ +
+
+
+
+
@@ -342,6 +446,17 @@ else private string _newDisplayName = ""; private bool _forceLoggingOut; + // Grant cards + private string _grantSearch = ""; + private bool _grantSearching; + private bool _grantSearched; + private List _grantResults = new(); + private CardDefinition? _selectedDef; + private int _grantQty = 1; + private bool _grantTradeable = true; + private bool _grantFoil; + private bool _granting; + // Account properties private List _props = new(); private Guid _editingPropId = Guid.Empty; @@ -530,6 +645,63 @@ else } } + // ── Grant Cards ─────────────────────────────────────────────────────────── + + private async Task GrantSearchAsync() + { + var term = _grantSearch.Trim(); + if (string.IsNullOrEmpty(term)) return; + + _grantSearching = true; + _grantSearched = false; + _selectedDef = null; + _grantResults = await CatalogDb.CardDefinitions + .Where(d => EF.Functions.ILike(d.Name, $"%{term}%")) + .OrderBy(d => d.Name) + .Take(20) + .ToListAsync(); + _grantSearching = false; + _grantSearched = true; + } + + private async Task GrantCardsAsync() + { + if (_account == null || _selectedDef == null) return; + _granting = true; + try + { + var qty = Math.Clamp(_grantQty, 1, 99); + var now = DateTimeOffset.UtcNow; + for (var i = 0; i < qty; i++) + { + CollectionDb.PlayerCards.Add(new PlayerCard + { + Id = Guid.NewGuid(), + AccountId = _account.Id, + CardDefinitionId = _selectedDef.Id, + AcquiredAt = now, + IsFoil = _grantFoil, + IsTradeable = _grantTradeable, + }); + } + await CollectionDb.SaveChangesAsync(); + _message = $"Granted {qty}× \"{_selectedDef.Name}\" to {_account.DisplayName ?? _account.Email}."; + _isError = false; + _selectedDef = null; + _grantQty = 1; + _grantFoil = false; + } + catch (Exception ex) + { + _message = $"Grant failed: {ex.Message}"; + _isError = true; + } + finally + { + _granting = false; + } + } + // ── Account Properties ───────────────────────────────────────────────────── private void StartEditProp(AccountProperty prop)