51 lines
1.5 KiB
C#
51 lines
1.5 KiB
C#
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.Common;
|
|
using Pf2e.Database;
|
|
using Pf2e.Database.Model;
|
|
using Pf2e.Database.Model.Base;
|
|
using Pf2e.Database.Model.Enum;
|
|
using Pf2e.Database.Model.Structure;
|
|
using Pf2e.Web.Helpers;
|
|
|
|
namespace Pf2e.Web.Pages
|
|
{
|
|
public class EntityModel(Pf2eDbContext context) : PageModel
|
|
{
|
|
private readonly Pf2eDbContext _context = context;
|
|
|
|
public FullEntity FullEntity { get; set; } = null!;
|
|
public EntitySerializer.SerializationResult SerializationResult { get; set; } = null!;
|
|
|
|
public IActionResult OnGet(string type, string slug)
|
|
{
|
|
// Получаем тип сущности
|
|
EntityType entityType = EntityTypeModel.Enum<EntityType>(type);
|
|
|
|
// Находим сущность по slug и типу
|
|
Entity? entity = _context.Entities.FirstOrDefault(e =>
|
|
e.Slug == slug && e.Type == entityType
|
|
);
|
|
|
|
if (entity == null)
|
|
{
|
|
return NotFound();
|
|
}
|
|
|
|
// Создаём FullEntity
|
|
FullEntity = new(_context, entity);
|
|
|
|
// Сериализуем для отображения
|
|
EntitySerializer serializer = new();
|
|
SerializationResult = serializer.Serialize(FullEntity);
|
|
|
|
return Page();
|
|
}
|
|
}
|
|
}
|