Write.cshtml.cs 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. using Domain.Entities.Forum.Boards;
  2. using SharedKernel.Extensions;
  3. using MediatR;
  4. using Microsoft.AspNetCore.Mvc;
  5. using Microsoft.AspNetCore.Mvc.RazorPages;
  6. namespace Admin.Pages.Forum.Board.Meta;
  7. public class WriteModel(IMediator mediator) : PageModel
  8. {
  9. public int BoardID { get; set; }
  10. public List<(int ID, string Name)> BoardList { get; set; } = [];
  11. public string? QueryString { get; set; }
  12. [BindProperty]
  13. public InputModel Input { get; set; } = new();
  14. public sealed class InputModel
  15. {
  16. public int ID { get; set; }
  17. public int BoardID { get; set; }
  18. public bool ShowHeader { get; set; }
  19. public string? HeaderContent { get; set; }
  20. public bool ShowFooter { get; set; }
  21. public string? FooterContent { get; set; }
  22. public string? DefaultSubject { get; set; }
  23. public string? DefaultContent { get; set; }
  24. public bool AllowEditor { get; set; }
  25. public bool AllowPrefix { get; set; }
  26. public bool RequiredPrefix { get; set; }
  27. public bool AllowSecret { get; set; }
  28. public bool AllowTag { get; set; }
  29. public byte TagLimit { get; set; }
  30. public bool AllowImage { get; set; }
  31. public byte ImageUploadLimit { get; set; }
  32. public int ImageUploadMaxSize { get; set; }
  33. public bool AllowMedia { get; set; }
  34. public byte MediaUploadLimit { get; set; }
  35. public bool AllowFile { get; set; }
  36. public byte FileUploadLimit { get; set; }
  37. public int FileUploadMaxSize { get; set; }
  38. public string? FileUploadExtension { get; set; }
  39. }
  40. public async Task OnGetAsync(int id, CancellationToken ct)
  41. {
  42. BoardID = id;
  43. QueryString = Request.QueryString.ToString();
  44. var boards = await mediator.Send(new SearchBoards.Query(null, null, 1, 100), ct);
  45. BoardList = [..boards.List.Select(c => (c.ID, c.Name))];
  46. var meta = await mediator.Send(new GetBoardMeta.Query(id), ct);
  47. Input = new InputModel
  48. {
  49. ID = meta.ID,
  50. BoardID = meta.BoardID,
  51. ShowHeader = meta.Write.ShowHeader,
  52. HeaderContent = meta.Write.HeaderContent,
  53. ShowFooter = meta.Write.ShowFooter,
  54. FooterContent = meta.Write.FooterContent,
  55. DefaultSubject = meta.Write.DefaultSubject,
  56. DefaultContent = meta.Write.DefaultContent,
  57. AllowEditor = meta.Write.AllowEditor,
  58. AllowPrefix = meta.Write.AllowPrefix,
  59. RequiredPrefix = meta.Write.RequiredPrefix,
  60. AllowSecret = meta.Write.AllowSecret,
  61. AllowTag = meta.Write.AllowTag,
  62. TagLimit = meta.Write.TagLimit,
  63. AllowImage = meta.Write.AllowImage,
  64. ImageUploadLimit = meta.Write.ImageUploadLimit,
  65. ImageUploadMaxSize = meta.Write.ImageUploadMaxSize,
  66. AllowMedia = meta.Write.AllowMedia,
  67. MediaUploadLimit = meta.Write.MediaUploadLimit,
  68. AllowFile = meta.Write.AllowFile,
  69. FileUploadLimit = meta.Write.FileUploadLimit,
  70. FileUploadMaxSize = meta.Write.FileUploadMaxSize,
  71. FileUploadExtension = meta.Write.FileUploadExtension
  72. };
  73. }
  74. public async Task<IActionResult> OnPostAsync(CancellationToken ct)
  75. {
  76. try
  77. {
  78. if (!ModelState.IsValid)
  79. {
  80. throw new Exception(ModelState.GetErrorMessages());
  81. }
  82. await mediator.Send(new UpdateBoardMeta.Command(
  83. Input.ID,
  84. Input.BoardID,
  85. null, null,
  86. new BoardMetaWrite
  87. {
  88. ShowHeader = Input.ShowHeader,
  89. HeaderContent = Input.HeaderContent,
  90. ShowFooter = Input.ShowFooter,
  91. FooterContent = Input.FooterContent,
  92. DefaultSubject = Input.DefaultSubject,
  93. DefaultContent = Input.DefaultContent,
  94. AllowEditor = Input.AllowEditor,
  95. AllowPrefix = Input.AllowPrefix,
  96. RequiredPrefix = Input.RequiredPrefix,
  97. AllowSecret = Input.AllowSecret,
  98. AllowTag = Input.AllowTag,
  99. TagLimit = Input.TagLimit,
  100. AllowImage = Input.AllowImage,
  101. ImageUploadLimit = Input.ImageUploadLimit,
  102. ImageUploadMaxSize = Input.ImageUploadMaxSize,
  103. AllowMedia = Input.AllowMedia,
  104. MediaUploadLimit = Input.MediaUploadLimit,
  105. AllowFile = Input.AllowFile,
  106. FileUploadLimit = Input.FileUploadLimit,
  107. FileUploadMaxSize = Input.FileUploadMaxSize,
  108. FileUploadExtension = Input.FileUploadExtension
  109. },
  110. null, null, null, null, null, null), ct);
  111. TempData["SuccessMessage"] = "작성 설정이 저장되었습니다.";
  112. }
  113. catch (Exception e)
  114. {
  115. TempData["ErrorMessages"] = e.Message;
  116. }
  117. return Redirect($"/Forum/Board/Meta/Write/{Input.BoardID}{Request.QueryString}");
  118. }
  119. }