Consolidation

This commit is contained in:
gamer147
2026-05-25 16:34:24 -04:00
parent 9b051c444c
commit 8e913578ff
14 changed files with 566 additions and 280 deletions

View File

@@ -63,28 +63,4 @@ public class PackRepository : IPackRepository
await _db.SaveChangesAsync();
}
public async Task GrantCardsToViewer(long viewerId, IEnumerable<long> cardIds)
{
var viewer = await _db.Viewers
.Include(v => v.Cards).ThenInclude(c => c.Card)
.FirstAsync(v => v.Id == viewerId);
var byId = viewer.Cards.ToDictionary(c => c.Card.Id);
foreach (var grp in cardIds.GroupBy(id => id))
{
if (byId.TryGetValue(grp.Key, out var existing))
{
existing.Count += grp.Count();
}
else
{
// Look up the card by id and attach it so we don't insert a phantom Card row.
var card = await _db.Cards.FirstAsync(c => c.Id == grp.Key);
var owned = new OwnedCardEntry { Card = card, Count = grp.Count(), IsProtected = false };
viewer.Cards.Add(owned);
byId[grp.Key] = owned;
}
}
await _db.SaveChangesAsync();
}
}