admin: fix RemoveCard DbUpdateConcurrencyException on save

PrebuiltDeckCard.Id is always a NewGuid() (never Guid.Empty), so the
old `if (entry.Id != Guid.Empty) Db.PrebuiltDeckCards.Remove(entry)`
guard was always true. When a user added a card then removed it before
saving, EF detached the Added entity from the collection, then the
explicit Db.Remove re-attached it as Deleted. SaveChangesAsync then
tried to DELETE a row that was never inserted → DbUpdateConcurrencyException.

Drop the explicit remove call entirely. EF Core automatically marks
Unchanged orphans as Deleted when removed from a required relationship
collection, and simply detaches Added orphans — both are the correct
outcomes without any extra Db.Remove.

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-03-01 09:22:38 -05:00
co-authored by Claude Happy
parent 59af920479
commit 0607f02e93
@@ -377,8 +377,10 @@ else
private void RemoveCard(PrebuiltDeckCard entry) private void RemoveCard(PrebuiltDeckCard entry)
{ {
_deck!.Cards.Remove(entry); _deck!.Cards.Remove(entry);
if (entry.Id != Guid.Empty) // EF automatically marks Unchanged cards as Deleted when removed from a required
Db.PrebuiltDeckCards.Remove(entry); // relationship collection (client-side cascade). For Added (unsaved) cards, EF
// detaches them — calling Db.Remove on a detached entity would re-attach it as
// Deleted and cause a 0-rows-affected DbUpdateConcurrencyException on save.
} }
private async Task SaveAsync() private async Task SaveAsync()