namespace SOR.Website.Pages.Cards; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.RazorPages; using Microsoft.EntityFrameworkCore; using SOR.Database.Contexts; using SOR.Database.Entities.Catalog; using SOR.Database.Enums; /// /// Individual card detail page. /// /// Security controls: /// - Card ID is a GUID — cannot be manipulated to traverse to other resources. /// - Only published, non-retired cards are shown; unpublished cards return 404. /// - All card data rendered through Razor's auto-encoding (no Html.Raw). /// public sealed class DetailsModel(CatalogDbContext catalog) : PageModel { public CardDefinition? Card { get; private set; } public IList RelatedCards { get; private set; } = []; public async Task OnGetAsync(Guid id) { Card = await catalog.CardDefinitions .Include(c => c.Set) .Include(c => c.Assets) .Include(c => c.PreviousTier) .Where(c => c.Id == id && c.IsPublished && !c.IsRetired && c.CardType != CardType.SpiritToken) .AsNoTracking() .FirstOrDefaultAsync(); if (Card is null) return NotFound(); // Load related cards: same set, same type, different card if (Card.SetId.HasValue) { RelatedCards = await catalog.CardDefinitions .Where(c => c.SetId == Card.SetId && c.CardType == Card.CardType && c.Id != Card.Id && c.IsPublished && !c.IsRetired) .OrderBy(c => c.Name) .Take(6) .AsNoTracking() .ToListAsync(); } ViewData["Title"] = Card.Name; ViewData["MetaDescription"] = Card.Description.Length > 160 ? Card.Description[..160] : Card.Description; return Page(); } }