using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.Linq; using System.Text; using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Identity; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.RazorPages; using Microsoft.AspNetCore.Mvc.Rendering; using Microsoft.EntityFrameworkCore; using ZpcBulletinBoard.Data; using ZpcBulletinBoard.Models; using ZpcBulletinBoard.Models.Editor; namespace ZpcBulletinBoard.Pages.Boards { [AllowAnonymous] public class ViewModel(ApplicationDbContext context) : PageModel { [BindProperty] public string Guid { get; set; } = ""; public IActionResult OnGet(string? guid) { if (string.IsNullOrEmpty(guid)) { return NotFound(); } Guid = guid; return Page(); } //GET public IActionResult OnGetPages(string guid) { var board = context.BulletinBoards .Include(x => x.Links.OrderBy(x => x.Order)) .ThenInclude(x => x.BulletinBoardPage) .FirstOrDefault(x => x.Guid.ToString() == guid); var links = new List(); if (board is not { Links: not null }) return new JsonResult(new { successful = true, links }); links.AddRange(board.Links); foreach (var link in links) { link.BulletinBoardPage.Links = null; link.BulletinBoard.Links = null; } return new JsonResult(new { successful = true, links }); } } }