Add collection service — deck management + card inventory
SOR.Collection project (new):
- 8 message handlers over WebSocket: get_cards, get_decks, get_deck,
create_deck, rename_deck, delete_deck, add_card, remove_card
- Deck construction rules (DeckRules.cs): min 20 / max 40 cards,
max 4 copies per definition, max 20 decks per player
- add_card validates ownership (player must own enough physical copies),
copy limit, deck size limit, and rejects ArchSpirits from the card list
- RefreshValidityAsync recalculates Deck.IsValid after every mutation
- Cross-context lookups (CollectionDbContext + CatalogDbContext) with
batch queries — never N+1
Admin portal pages (new):
- /collection — overview stats (total cards, total decks, valid decks,
unique players) + account ID lookup
- /collection/player/{accountId} — full player collection viewer:
paginated card grid with name/type/affinity/rarity/foil/serial filters,
deck list with expanded card tables, Grant Card modal (search + foil
toggle, grants 1–100 copies), revoke individual card instances
Wiring:
- SOR.slnx + SOR.Host.csproj: added SOR.Collection project reference
- Program.cs: uncommented collection service registration
- NavMenu: added Collection item
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:
@@ -0,0 +1,95 @@
|
||||
@page "/collection"
|
||||
@attribute [Authorize(Roles = "Admin,SuperAdmin")]
|
||||
@inject CollectionDbContext CollectionDb
|
||||
@inject NavigationManager Nav
|
||||
|
||||
<PageTitle>Collection – SOR Admin</PageTitle>
|
||||
|
||||
<h1 class="mb-4">Collection</h1>
|
||||
|
||||
<div class="row g-4 mb-4">
|
||||
<div class="col-sm-6 col-lg-3">
|
||||
<div class="card shadow-sm">
|
||||
<div class="card-body">
|
||||
<div class="text-muted small mb-1">Total Player Cards</div>
|
||||
<div class="fs-3 fw-bold text-primary">@(_totalCards?.ToString("N0") ?? "…")</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-sm-6 col-lg-3">
|
||||
<div class="card shadow-sm">
|
||||
<div class="card-body">
|
||||
<div class="text-muted small mb-1">Total Decks</div>
|
||||
<div class="fs-3 fw-bold">@(_totalDecks?.ToString("N0") ?? "…")</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-sm-6 col-lg-3">
|
||||
<div class="card shadow-sm">
|
||||
<div class="card-body">
|
||||
<div class="text-muted small mb-1">Valid Decks</div>
|
||||
<div class="fs-3 fw-bold text-success">@(_validDecks?.ToString("N0") ?? "…")</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-sm-6 col-lg-3">
|
||||
<div class="card shadow-sm">
|
||||
<div class="card-body">
|
||||
<div class="text-muted small mb-1">Unique Players w/ Cards</div>
|
||||
<div class="fs-3 fw-bold text-info">@(_uniquePlayers?.ToString("N0") ?? "…")</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="card shadow-sm">
|
||||
<div class="card-header fw-medium">Look Up Player Collection</div>
|
||||
<div class="card-body">
|
||||
<div class="row g-2 align-items-end">
|
||||
<div class="col-md-8">
|
||||
<label class="form-label">Account ID (GUID)</label>
|
||||
<input @bind="_accountIdInput" class="form-control" placeholder="xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" />
|
||||
</div>
|
||||
<div class="col-md-4">
|
||||
<button class="btn btn-primary w-100" @onclick="GoToPlayer">
|
||||
<i class="bi bi-search me-1"></i>View Collection
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
@if (_lookupError != null)
|
||||
{
|
||||
<div class="alert alert-danger mt-2 mb-0">@_lookupError</div>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@code {
|
||||
private int? _totalCards;
|
||||
private int? _totalDecks;
|
||||
private int? _validDecks;
|
||||
private int? _uniquePlayers;
|
||||
private string _accountIdInput = string.Empty;
|
||||
private string? _lookupError;
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
_totalCards = await CollectionDb.PlayerCards.CountAsync();
|
||||
_totalDecks = await CollectionDb.Decks.CountAsync();
|
||||
_validDecks = await CollectionDb.Decks.CountAsync(d => d.IsValid);
|
||||
_uniquePlayers = await CollectionDb.PlayerCards
|
||||
.Select(pc => pc.AccountId)
|
||||
.Distinct()
|
||||
.CountAsync();
|
||||
}
|
||||
|
||||
private void GoToPlayer()
|
||||
{
|
||||
_lookupError = null;
|
||||
if (!Guid.TryParse(_accountIdInput?.Trim(), out var id))
|
||||
{
|
||||
_lookupError = "Please enter a valid GUID.";
|
||||
return;
|
||||
}
|
||||
Nav.NavigateTo($"/collection/player/{id}");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,511 @@
|
||||
@page "/collection/player/{AccountId:guid}"
|
||||
@attribute [Authorize(Roles = "Admin,SuperAdmin")]
|
||||
@inject CollectionDbContext CollectionDb
|
||||
@inject CatalogDbContext CatalogDb
|
||||
@inject SOR.Database.Contexts.SorIdentityDbContext IdentityDb
|
||||
|
||||
<PageTitle>Player Collection – SOR Admin</PageTitle>
|
||||
|
||||
@if (_loaded)
|
||||
{
|
||||
<div class="d-flex justify-content-between align-items-center mb-4">
|
||||
<div>
|
||||
<a href="/collection" class="text-muted text-decoration-none small">
|
||||
<i class="bi bi-arrow-left me-1"></i>Collection
|
||||
</a>
|
||||
<h1 class="mb-0 mt-1">
|
||||
<i class="bi bi-person-circle me-2 text-muted"></i>
|
||||
@(_displayName ?? AccountId.ToString())
|
||||
</h1>
|
||||
<div class="text-muted small">@AccountId</div>
|
||||
</div>
|
||||
<button class="btn btn-outline-primary btn-sm" @onclick="() => _showGrant = true">
|
||||
<i class="bi bi-plus-circle me-1"></i>Grant Card
|
||||
</button>
|
||||
</div>
|
||||
|
||||
@if (_grantSuccess != null) { <div class="alert alert-success">@_grantSuccess</div> }
|
||||
@if (_grantError != null) { <div class="alert alert-danger">@_grantError</div> }
|
||||
|
||||
<!-- Tab switcher -->
|
||||
<ul class="nav nav-tabs mb-3">
|
||||
<li class="nav-item">
|
||||
<button class="nav-link @(_tab == "cards" ? "active" : "")" @onclick='() => _tab = "cards"'>
|
||||
<i class="bi bi-collection me-1"></i>Cards
|
||||
<span class="badge bg-secondary ms-1">@_totalCards</span>
|
||||
</button>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<button class="nav-link @(_tab == "decks" ? "active" : "")" @onclick='() => _tab = "decks"'>
|
||||
<i class="bi bi-stack me-1"></i>Decks
|
||||
<span class="badge bg-secondary ms-1">@_decks.Count</span>
|
||||
</button>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
<!-- ── Cards tab ───────────────────────────────────────────────────── -->
|
||||
@if (_tab == "cards")
|
||||
{
|
||||
<div class="row g-2 mb-3">
|
||||
<div class="col-md-5">
|
||||
<input @bind="_cardSearch" class="form-control form-control-sm"
|
||||
placeholder="Search by name…" @bind:event="oninput" @bind:after="OnCardSearchChanged" />
|
||||
</div>
|
||||
<div class="col-md-3">
|
||||
<select @bind="_cardTypeFilter" class="form-select form-select-sm" @bind:after="LoadCardsAsync">
|
||||
<option value="">All types</option>
|
||||
@foreach (var t in Enum.GetValues<CardType>())
|
||||
{
|
||||
<option value="@t">@t</option>
|
||||
}
|
||||
</select>
|
||||
</div>
|
||||
<div class="col-md-3">
|
||||
<select @bind="_rarityFilter" class="form-select form-select-sm" @bind:after="LoadCardsAsync">
|
||||
<option value="">All rarities</option>
|
||||
@foreach (var r in Enum.GetValues<CardRarity>())
|
||||
{
|
||||
<option value="@r">@r</option>
|
||||
}
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@if (_cards == null)
|
||||
{
|
||||
<p class="text-muted">Loading…</p>
|
||||
}
|
||||
else if (_cards.Count == 0)
|
||||
{
|
||||
<p class="text-muted">No cards found.</p>
|
||||
}
|
||||
else
|
||||
{
|
||||
<table class="table table-sm table-hover">
|
||||
<thead class="table-dark">
|
||||
<tr>
|
||||
<th>Name</th>
|
||||
<th>Type</th>
|
||||
<th>Affinity</th>
|
||||
<th>Rarity</th>
|
||||
<th>Foil</th>
|
||||
<th>#</th>
|
||||
<th>Acquired</th>
|
||||
<th style="width:50px"></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach (var row in _cards)
|
||||
{
|
||||
var r = row;
|
||||
<tr>
|
||||
<td class="fw-medium">@r.Name</td>
|
||||
<td><span class="badge bg-secondary">@r.CardType</span></td>
|
||||
<td>@r.Affinity</td>
|
||||
<td>@r.Rarity</td>
|
||||
<td>@(r.IsFoil ? "✦" : "")</td>
|
||||
<td class="text-muted small">@(r.SerialNumber?.ToString() ?? "—")</td>
|
||||
<td class="text-muted small">@r.AcquiredAt.ToString("yyyy-MM-dd")</td>
|
||||
<td>
|
||||
<button class="btn btn-sm btn-outline-danger"
|
||||
@onclick="() => RevokeCardAsync(r.PlayerCardId)"
|
||||
title="Revoke this card">
|
||||
<i class="bi bi-trash"></i>
|
||||
</button>
|
||||
</td>
|
||||
</tr>
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<!-- Pagination -->
|
||||
<div class="d-flex justify-content-between align-items-center">
|
||||
<span class="text-muted small">
|
||||
Showing @((_cardPage - 1) * PageSize + 1)–@(Math.Min(_cardPage * PageSize, _totalCards)) of @_totalCards
|
||||
</span>
|
||||
<div class="btn-group btn-group-sm">
|
||||
<button class="btn btn-outline-secondary" disabled="@(_cardPage <= 1)"
|
||||
@onclick="() => GoToCardPage(_cardPage - 1)">
|
||||
<i class="bi bi-chevron-left"></i>
|
||||
</button>
|
||||
<button class="btn btn-outline-secondary" disabled="@(_cardPage * PageSize >= _totalCards)"
|
||||
@onclick="() => GoToCardPage(_cardPage + 1)">
|
||||
<i class="bi bi-chevron-right"></i>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
}
|
||||
|
||||
<!-- ── Decks tab ──────────────────────────────────────────────────── -->
|
||||
@if (_tab == "decks")
|
||||
{
|
||||
@if (_decks.Count == 0)
|
||||
{
|
||||
<p class="text-muted">This player has no decks.</p>
|
||||
}
|
||||
else
|
||||
{
|
||||
@foreach (var deck in _decks)
|
||||
{
|
||||
var d = deck;
|
||||
<div class="card shadow-sm mb-3">
|
||||
<div class="card-header d-flex justify-content-between align-items-center">
|
||||
<div>
|
||||
<span class="fw-medium">@d.Name</span>
|
||||
@if (d.IsValid)
|
||||
{
|
||||
<span class="badge bg-success ms-2">Valid</span>
|
||||
}
|
||||
else
|
||||
{
|
||||
<span class="badge bg-warning text-dark ms-2">Invalid</span>
|
||||
}
|
||||
</div>
|
||||
<div class="text-muted small">
|
||||
ArchSpirit: <strong>@(d.ArchSpiritName ?? d.ArchSpiritCardDefinitionId.ToString())</strong>
|
||||
· @d.TotalCards card@(d.TotalCards == 1 ? "" : "s")
|
||||
</div>
|
||||
</div>
|
||||
@if (d.Cards.Count > 0)
|
||||
{
|
||||
<div class="card-body p-0">
|
||||
<table class="table table-sm mb-0">
|
||||
<thead><tr><th>Card</th><th>Type</th><th>Affinity</th><th style="width:80px">Qty</th></tr></thead>
|
||||
<tbody>
|
||||
@foreach (var card in d.Cards)
|
||||
{
|
||||
<tr>
|
||||
<td>@card.Name</td>
|
||||
<td><span class="badge bg-secondary">@card.CardType</span></td>
|
||||
<td>@card.Affinity</td>
|
||||
<td>×@card.Quantity</td>
|
||||
</tr>
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
<!-- ── Grant Card modal ───────────────────────────────────────────── -->
|
||||
@if (_showGrant)
|
||||
{
|
||||
<div class="modal fade show d-block" tabindex="-1" style="background:rgba(0,0,0,.5)">
|
||||
<div class="modal-dialog">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title">Grant Card</h5>
|
||||
<button class="btn-close" @onclick="CloseGrant"></button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<div class="mb-3">
|
||||
<label class="form-label">Search Card</label>
|
||||
<div class="input-group">
|
||||
<input @bind="_grantSearch" class="form-control" placeholder="Card name…" />
|
||||
<button class="btn btn-outline-secondary" @onclick="SearchGrantCardAsync">
|
||||
<i class="bi bi-search"></i>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
@if (_grantResults.Count > 0)
|
||||
{
|
||||
<div class="list-group mb-3">
|
||||
@foreach (var cd in _grantResults)
|
||||
{
|
||||
var c = cd;
|
||||
<button class="list-group-item list-group-item-action py-1 @(_grantSelected?.Id == c.Id ? "active" : "")"
|
||||
@onclick="() => _grantSelected = c">
|
||||
<span class="fw-medium">@c.Name</span>
|
||||
<span class="badge bg-secondary ms-2">@c.CardType</span>
|
||||
<span class="text-muted small ms-1">@c.Affinity · @c.Rarity</span>
|
||||
</button>
|
||||
}
|
||||
</div>
|
||||
}
|
||||
@if (_grantSelected != null)
|
||||
{
|
||||
<div class="mb-3">
|
||||
<label class="form-label">Copies to Grant</label>
|
||||
<input @bind="_grantQty" type="number" min="1" max="100" class="form-control" />
|
||||
</div>
|
||||
<div class="mb-0">
|
||||
<div class="form-check">
|
||||
<input @bind="_grantFoil" type="checkbox" class="form-check-input" id="chkFoil" />
|
||||
<label class="form-check-label" for="chkFoil">Foil</label>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button class="btn btn-secondary" @onclick="CloseGrant">Cancel</button>
|
||||
<button class="btn btn-primary" @onclick="GrantCardAsync"
|
||||
disabled="@(_grantSelected == null || _granting)">
|
||||
@if (_granting) { <span class="spinner-border spinner-border-sm me-1"></span> }
|
||||
<i class="bi bi-gift me-1"></i>Grant @_grantQty
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
<p class="text-muted">Loading…</p>
|
||||
}
|
||||
|
||||
@code {
|
||||
[Parameter] public Guid AccountId { get; set; }
|
||||
|
||||
private const int PageSize = 50;
|
||||
|
||||
// State
|
||||
private bool _loaded;
|
||||
private string? _displayName;
|
||||
private string _tab = "cards";
|
||||
|
||||
// Cards tab
|
||||
private List<PlayerCardRow>? _cards;
|
||||
private int _totalCards;
|
||||
private int _cardPage = 1;
|
||||
private string _cardSearch = string.Empty;
|
||||
private string _cardTypeFilter = string.Empty;
|
||||
private string _rarityFilter = string.Empty;
|
||||
|
||||
// Decks tab
|
||||
private List<DeckRow> _decks = new();
|
||||
|
||||
// Grant modal
|
||||
private bool _showGrant;
|
||||
private string _grantSearch = string.Empty;
|
||||
private List<CardDefinition> _grantResults = new();
|
||||
private CardDefinition? _grantSelected;
|
||||
private int _grantQty = 1;
|
||||
private bool _grantFoil;
|
||||
private bool _granting;
|
||||
private string? _grantSuccess;
|
||||
private string? _grantError;
|
||||
|
||||
// View models
|
||||
private sealed class PlayerCardRow
|
||||
{
|
||||
public Guid PlayerCardId { get; init; }
|
||||
public Guid CardDefinitionId { get; init; }
|
||||
public string Name { get; init; } = "";
|
||||
public string CardType { get; init; } = "";
|
||||
public string Affinity { get; init; } = "";
|
||||
public string Rarity { get; init; } = "";
|
||||
public bool IsFoil { get; init; }
|
||||
public int? SerialNumber { get; init; }
|
||||
public DateTimeOffset AcquiredAt { get; init; }
|
||||
}
|
||||
|
||||
private sealed class DeckRow
|
||||
{
|
||||
public Guid Id { get; init; }
|
||||
public string Name { get; init; } = "";
|
||||
public Guid ArchSpiritCardDefinitionId { get; init; }
|
||||
public string? ArchSpiritName { get; init; }
|
||||
public bool IsValid { get; init; }
|
||||
public int TotalCards { get; init; }
|
||||
public List<DeckCardRow> Cards { get; init; } = new();
|
||||
}
|
||||
|
||||
private sealed class DeckCardRow
|
||||
{
|
||||
public Guid CardDefinitionId { get; init; }
|
||||
public string Name { get; init; } = "";
|
||||
public string CardType { get; init; } = "";
|
||||
public string Affinity { get; init; } = "";
|
||||
public int Quantity { get; init; }
|
||||
}
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
// Fetch player display name from identity schema.
|
||||
_displayName = await IdentityDb.Users
|
||||
.Where(u => u.Id == AccountId)
|
||||
.Select(u => u.DisplayName)
|
||||
.FirstOrDefaultAsync();
|
||||
|
||||
await LoadCardsAsync();
|
||||
await LoadDecksAsync();
|
||||
_loaded = true;
|
||||
}
|
||||
|
||||
private async Task LoadCardsAsync()
|
||||
{
|
||||
var query = CollectionDb.PlayerCards
|
||||
.Where(pc => pc.AccountId == AccountId);
|
||||
|
||||
// Cross-context filters: resolve matching definition IDs first.
|
||||
if (!string.IsNullOrWhiteSpace(_cardSearch)
|
||||
|| !string.IsNullOrEmpty(_cardTypeFilter)
|
||||
|| !string.IsNullOrEmpty(_rarityFilter))
|
||||
{
|
||||
var defQ = CatalogDb.CardDefinitions.AsQueryable();
|
||||
if (!string.IsNullOrWhiteSpace(_cardSearch))
|
||||
defQ = defQ.Where(cd => cd.Name.Contains(_cardSearch));
|
||||
if (!string.IsNullOrEmpty(_cardTypeFilter)
|
||||
&& Enum.TryParse<CardType>(_cardTypeFilter, out var ctf))
|
||||
defQ = defQ.Where(cd => cd.CardType == ctf);
|
||||
if (!string.IsNullOrEmpty(_rarityFilter)
|
||||
&& Enum.TryParse<CardRarity>(_rarityFilter, out var rf))
|
||||
defQ = defQ.Where(cd => cd.Rarity == rf);
|
||||
|
||||
var matchIds = await defQ.Select(cd => cd.Id).ToListAsync();
|
||||
query = query.Where(pc => matchIds.Contains(pc.CardDefinitionId));
|
||||
}
|
||||
|
||||
_totalCards = await query.CountAsync();
|
||||
int skip = (_cardPage - 1) * PageSize;
|
||||
|
||||
var playerCards = await query
|
||||
.OrderBy(pc => pc.AcquiredAt)
|
||||
.Skip(skip).Take(PageSize)
|
||||
.ToListAsync();
|
||||
|
||||
var defIds = playerCards.Select(pc => pc.CardDefinitionId).Distinct().ToList();
|
||||
var defLookup = await CatalogDb.CardDefinitions
|
||||
.Where(cd => defIds.Contains(cd.Id))
|
||||
.ToDictionaryAsync(cd => cd.Id);
|
||||
|
||||
_cards = playerCards.Select(pc =>
|
||||
{
|
||||
defLookup.TryGetValue(pc.CardDefinitionId, out var def);
|
||||
return new PlayerCardRow
|
||||
{
|
||||
PlayerCardId = pc.Id,
|
||||
CardDefinitionId = pc.CardDefinitionId,
|
||||
Name = def?.Name ?? "Unknown",
|
||||
CardType = def?.CardType.ToString() ?? "Unknown",
|
||||
Affinity = def?.Affinity.ToString() ?? "Unknown",
|
||||
Rarity = def?.Rarity.ToString() ?? "Unknown",
|
||||
IsFoil = pc.IsFoil,
|
||||
SerialNumber = pc.SerialNumber,
|
||||
AcquiredAt = pc.AcquiredAt,
|
||||
};
|
||||
}).ToList();
|
||||
}
|
||||
|
||||
private async Task LoadDecksAsync()
|
||||
{
|
||||
var decks = await CollectionDb.Decks
|
||||
.Include(d => d.Cards)
|
||||
.Where(d => d.AccountId == AccountId)
|
||||
.OrderBy(d => d.CreatedAt)
|
||||
.ToListAsync();
|
||||
|
||||
// Batch-load definitions for arch spirits + deck cards.
|
||||
var allDefIds = decks
|
||||
.SelectMany(d => d.Cards.Select(c => c.CardDefinitionId).Append(d.ArchSpiritCardDefinitionId))
|
||||
.Distinct()
|
||||
.ToList();
|
||||
var defs = await CatalogDb.CardDefinitions
|
||||
.Where(cd => allDefIds.Contains(cd.Id))
|
||||
.ToDictionaryAsync(cd => cd.Id);
|
||||
|
||||
_decks = decks.Select(d =>
|
||||
{
|
||||
defs.TryGetValue(d.ArchSpiritCardDefinitionId, out var archDef);
|
||||
return new DeckRow
|
||||
{
|
||||
Id = d.Id,
|
||||
Name = d.Name,
|
||||
ArchSpiritCardDefinitionId = d.ArchSpiritCardDefinitionId,
|
||||
ArchSpiritName = archDef?.Name,
|
||||
IsValid = d.IsValid,
|
||||
TotalCards = d.Cards.Sum(c => c.Quantity),
|
||||
Cards = d.Cards
|
||||
.OrderBy(c => defs.TryGetValue(c.CardDefinitionId, out var cd) ? cd.Name : "")
|
||||
.Select(c =>
|
||||
{
|
||||
defs.TryGetValue(c.CardDefinitionId, out var cd);
|
||||
return new DeckCardRow
|
||||
{
|
||||
CardDefinitionId = c.CardDefinitionId,
|
||||
Name = cd?.Name ?? "Unknown",
|
||||
CardType = cd?.CardType.ToString() ?? "",
|
||||
Affinity = cd?.Affinity.ToString() ?? "",
|
||||
Quantity = c.Quantity,
|
||||
};
|
||||
}).ToList(),
|
||||
};
|
||||
}).ToList();
|
||||
}
|
||||
|
||||
private async Task GoToCardPage(int page)
|
||||
{
|
||||
_cardPage = page;
|
||||
await LoadCardsAsync();
|
||||
}
|
||||
|
||||
private async Task OnCardSearchChanged()
|
||||
{
|
||||
_cardPage = 1;
|
||||
await LoadCardsAsync();
|
||||
}
|
||||
|
||||
private async Task RevokeCardAsync(Guid playerCardId)
|
||||
{
|
||||
_grantSuccess = _grantError = null;
|
||||
var card = await CollectionDb.PlayerCards.FindAsync(playerCardId);
|
||||
if (card == null || card.AccountId != AccountId) return;
|
||||
CollectionDb.PlayerCards.Remove(card);
|
||||
await CollectionDb.SaveChangesAsync();
|
||||
await LoadCardsAsync();
|
||||
}
|
||||
|
||||
// ── Grant modal ──────────────────────────────────────────────────────────
|
||||
|
||||
private void CloseGrant()
|
||||
{
|
||||
_showGrant = false;
|
||||
_grantSearch = string.Empty;
|
||||
_grantResults.Clear();
|
||||
_grantSelected = null;
|
||||
_grantQty = 1;
|
||||
_grantFoil = false;
|
||||
}
|
||||
|
||||
private async Task SearchGrantCardAsync()
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(_grantSearch)) return;
|
||||
_grantResults = await CatalogDb.CardDefinitions
|
||||
.Where(cd => cd.Name.Contains(_grantSearch))
|
||||
.OrderBy(cd => cd.Name)
|
||||
.Take(20)
|
||||
.ToListAsync();
|
||||
}
|
||||
|
||||
private async Task GrantCardAsync()
|
||||
{
|
||||
if (_grantSelected == null) return;
|
||||
_granting = true; _grantError = null; _grantSuccess = null;
|
||||
try
|
||||
{
|
||||
int qty = Math.Clamp(_grantQty, 1, 100);
|
||||
var now = DateTimeOffset.UtcNow;
|
||||
for (int i = 0; i < qty; i++)
|
||||
{
|
||||
CollectionDb.PlayerCards.Add(new SOR.Database.Entities.Collection.PlayerCard
|
||||
{
|
||||
AccountId = AccountId,
|
||||
CardDefinitionId = _grantSelected.Id,
|
||||
AcquiredAt = now,
|
||||
IsFoil = _grantFoil,
|
||||
});
|
||||
}
|
||||
await CollectionDb.SaveChangesAsync();
|
||||
_grantSuccess = $"Granted {qty}× {_grantSelected.Name}{(_grantFoil ? " (Foil)" : "")} to player.";
|
||||
CloseGrant();
|
||||
await LoadCardsAsync();
|
||||
}
|
||||
catch (Exception ex) { _grantError = ex.Message; }
|
||||
finally { _granting = false; }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user