Add Grant Card section to AccountDetail admin page

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 <noreply@anthropic.com>
Co-Authored-By: Happy <yesreply@happy.engineering>
This commit is contained in:
dingo
2026-02-28 13:45:37 -05:00
co-authored by Claude Happy
parent a24e3ea17c
commit fd8fe950f8
@@ -1,12 +1,15 @@
@page "/accounts/{Id:guid}"
@attribute [Authorize(Roles = "Admin,SuperAdmin")]
@inject SorIdentityDbContext Db
@inject CatalogDbContext CatalogDb
@inject CollectionDbContext CollectionDb
@inject UserManager<Account> UserManager
@inject NavigationManager Nav
@inject IConnectionMultiplexer Redis
@using Microsoft.AspNetCore.Identity
@using StackExchange.Redis
@using SOR.Shared.Redis
@using SOR.Database.Entities.Collection
<PageTitle>Account – SOR Admin</PageTitle>
@@ -236,6 +239,107 @@ else
</div>
</div>
<!-- Grant Cards -->
<div class="col-12">
<div class="card shadow-sm">
<div class="card-header fw-medium">Grant Cards</div>
<div class="card-body">
<!-- Search -->
<div class="d-flex gap-2 mb-3">
<input @bind="_grantSearch" @bind:event="oninput"
@onkeydown="@(async e => { if (e.Key == "Enter") await GrantSearchAsync(); })"
type="text" class="form-control form-control-sm"
placeholder="Search card definitions by name…" />
<button class="btn btn-sm btn-outline-secondary" @onclick="GrantSearchAsync"
disabled="@_grantSearching">
@if (_grantSearching)
{
<span class="spinner-border spinner-border-sm"></span>
}
else
{
<i class="bi bi-search"></i>
}
</button>
</div>
<!-- Results -->
@if (_grantResults.Count > 0)
{
<div class="mb-3" style="max-height:260px;overflow-y:auto;border:1px solid #333;border-radius:6px;">
<table class="table table-sm table-hover mb-0">
<thead class="sticky-top bg-dark">
<tr>
<th>Name</th>
<th style="width:110px">Type</th>
<th style="width:100px">Affinity</th>
<th style="width:110px">Rarity</th>
</tr>
</thead>
<tbody>
@foreach (var def in _grantResults)
{
var d = def;
var isSelected = _selectedDef?.Id == d.Id;
<tr class="@(isSelected ? "table-primary" : "")"
style="cursor:pointer"
@onclick="() => _selectedDef = d">
<td>@d.Name</td>
<td>@d.CardType</td>
<td>@d.Affinity</td>
<td>@d.Rarity</td>
</tr>
}
</tbody>
</table>
</div>
}
else if (_grantSearched)
{
<p class="text-muted small mb-3">No card definitions found.</p>
}
<!-- Grant controls -->
<div class="d-flex flex-wrap gap-3 align-items-end">
<div>
<label class="form-label small mb-1">Selected Card</label>
<div class="form-control-plaintext form-control-sm fw-medium"
style="min-width:200px">
@(_selectedDef?.Name ?? "—")
</div>
</div>
<div>
<label class="form-label small mb-1">Quantity</label>
<input @bind="_grantQty" type="number" min="1" max="99"
class="form-control form-control-sm" style="width:80px" />
</div>
<div class="d-flex gap-3 pb-1">
<div class="form-check form-check-inline mb-0">
<input @bind="_grantTradeable" class="form-check-input" type="checkbox" id="grantTradeable" />
<label class="form-check-label small" for="grantTradeable">Tradeable</label>
</div>
<div class="form-check form-check-inline mb-0">
<input @bind="_grantFoil" class="form-check-input" type="checkbox" id="grantFoil" />
<label class="form-check-label small" for="grantFoil">Foil</label>
</div>
</div>
<button class="btn btn-sm btn-success" @onclick="GrantCardsAsync"
disabled="@(_selectedDef == null || _granting)">
@if (_granting)
{
<span class="spinner-border spinner-border-sm me-1"></span>
}
else
{
<i class="bi bi-gift me-1"></i>
}
Grant
</button>
</div>
</div>
</div>
</div>
<!-- Account Properties -->
<div class="col-12">
<div class="card shadow-sm">
@@ -342,6 +446,17 @@ else
private string _newDisplayName = "";
private bool _forceLoggingOut;
// Grant cards
private string _grantSearch = "";
private bool _grantSearching;
private bool _grantSearched;
private List<CardDefinition> _grantResults = new();
private CardDefinition? _selectedDef;
private int _grantQty = 1;
private bool _grantTradeable = true;
private bool _grantFoil;
private bool _granting;
// Account properties
private List<AccountProperty> _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)