using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.RazorPages; using Microsoft.EntityFrameworkCore; using Pf2e.Database; using Pf2e.Database.Model; using Pf2e.Database.Model.Base; using Pf2e.Database.Model.Enum; using Pf2e.Database.Model.Structure; namespace Pf2e.Web.Pages { public class EntityModel : PageModel { private readonly Pf2e.Database.Pf2eDbContext _context; public EntityModel(Pf2e.Database.Pf2eDbContext context) { _context = context; } public IEntity Entity; public Dictionary Fields = []; public Dictionary> References = []; public async Task OnGetAsync(string type, string slug) { Entity entity = _context .Entities.Where(e => e.Slug == slug && e.Type == EntityTypeModel.Enum(type) ) .Include(e => e.Sources) .ThenInclude(s => s.Source) .Include(e => e.Keywords) .Include(e => e.Externals) .ThenInclude(x => x.Target) .Include(e => e.Traits) .ThenInclude(t => t.Entity) .FirstOrDefault() ?? throw new("Entity is null"); /* if (id == null) { return NotFound(); } var class = await _context.Classes.FirstOrDefaultAsync(m => m.Id == id); if (class is not null) { Class = class; return Page(); } */ return NotFound(); } } }