Работа над маршрутизацией
This commit is contained in:
@@ -15,6 +15,7 @@ using Pf2e.Web.Helpers;
|
||||
|
||||
namespace Pf2e.Web.Pages
|
||||
{
|
||||
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
|
||||
public class EntityModel(Pf2eDbContext context) : PageModel
|
||||
{
|
||||
private readonly Pf2eDbContext _context = context;
|
||||
@@ -24,27 +25,42 @@ namespace Pf2e.Web.Pages
|
||||
|
||||
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)
|
||||
// Добавим отладочную информацию
|
||||
System.Diagnostics.Debug.WriteLine($"EntityModel.OnGet called with type: {type}, slug: {slug}");
|
||||
|
||||
try
|
||||
{
|
||||
// Получаем тип сущности
|
||||
EntityType entityType = EntityTypeModel.Enum<EntityType>(type);
|
||||
System.Diagnostics.Debug.WriteLine($"EntityType resolved to: {entityType}");
|
||||
|
||||
// Находим сущность по slug и типу
|
||||
Entity? entity = _context.Entities.FirstOrDefault(e =>
|
||||
e.Slug.ToLower() == slug.ToLower() && e.Type == entityType
|
||||
);
|
||||
|
||||
if (entity == null)
|
||||
{
|
||||
System.Diagnostics.Debug.WriteLine($"Entity not found: type={entityType}, slug={slug}");
|
||||
return NotFound();
|
||||
}
|
||||
|
||||
System.Diagnostics.Debug.WriteLine($"Entity found: {entity.Id} - {entity.Name[Pf2e.Database.Model.Common.I18n.LocaleType.English]}");
|
||||
|
||||
// Создаём FullEntity
|
||||
FullEntity = new(_context, entity);
|
||||
|
||||
// Сериализуем для отображения
|
||||
EntitySerializer serializer = new();
|
||||
SerializationResult = serializer.Serialize(FullEntity);
|
||||
|
||||
return Page();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
System.Diagnostics.Debug.WriteLine($"Error in EntityModel.OnGet: {ex.Message}");
|
||||
return NotFound();
|
||||
}
|
||||
|
||||
// Создаём FullEntity
|
||||
FullEntity = new(_context, entity);
|
||||
|
||||
// Сериализуем для отображения
|
||||
EntitySerializer serializer = new();
|
||||
SerializationResult = serializer.Serialize(FullEntity);
|
||||
|
||||
return Page();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user