Write.cshtml.cs 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. using Domain.Entities.Forum.Boards;
  2. using SharedKernel.Extensions;
  3. using Application.Abstractions.Messaging;
  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 metaResult = await mediator.Send(new GetBoardMeta.Query(id), ct);
  47. if (metaResult.IsFailure)
  48. {
  49. TempData["ErrorMessages"] = metaResult.Error.Description;
  50. return;
  51. }
  52. var meta = metaResult.Value;
  53. Input = new InputModel
  54. {
  55. ID = meta.ID,
  56. BoardID = meta.BoardID,
  57. ShowHeader = meta.Write.ShowHeader,
  58. HeaderContent = meta.Write.HeaderContent,
  59. ShowFooter = meta.Write.ShowFooter,
  60. FooterContent = meta.Write.FooterContent,
  61. DefaultSubject = meta.Write.DefaultSubject,
  62. DefaultContent = meta.Write.DefaultContent,
  63. AllowEditor = meta.Write.AllowEditor,
  64. AllowPrefix = meta.Write.AllowPrefix,
  65. RequiredPrefix = meta.Write.RequiredPrefix,
  66. AllowSecret = meta.Write.AllowSecret,
  67. AllowTag = meta.Write.AllowTag,
  68. TagLimit = meta.Write.TagLimit,
  69. AllowImage = meta.Write.AllowImage,
  70. ImageUploadLimit = meta.Write.ImageUploadLimit,
  71. ImageUploadMaxSize = meta.Write.ImageUploadMaxSize,
  72. AllowMedia = meta.Write.AllowMedia,
  73. MediaUploadLimit = meta.Write.MediaUploadLimit,
  74. AllowFile = meta.Write.AllowFile,
  75. FileUploadLimit = meta.Write.FileUploadLimit,
  76. FileUploadMaxSize = meta.Write.FileUploadMaxSize,
  77. FileUploadExtension = meta.Write.FileUploadExtension
  78. };
  79. }
  80. public async Task<IActionResult> OnPostAsync(CancellationToken ct)
  81. {
  82. if (!ModelState.IsValid)
  83. {
  84. TempData["ErrorMessages"] = ModelState.GetErrorMessages();
  85. return Redirect($"/Forum/Board/Meta/Write/{Input.BoardID}{Request.QueryString}");
  86. }
  87. var result = await mediator.Send(new UpdateBoardMeta.Command(
  88. Input.ID,
  89. Input.BoardID,
  90. null, null,
  91. new BoardMetaWrite
  92. {
  93. ShowHeader = Input.ShowHeader,
  94. HeaderContent = Input.HeaderContent,
  95. ShowFooter = Input.ShowFooter,
  96. FooterContent = Input.FooterContent,
  97. DefaultSubject = Input.DefaultSubject,
  98. DefaultContent = Input.DefaultContent,
  99. AllowEditor = Input.AllowEditor,
  100. AllowPrefix = Input.AllowPrefix,
  101. RequiredPrefix = Input.RequiredPrefix,
  102. AllowSecret = Input.AllowSecret,
  103. AllowTag = Input.AllowTag,
  104. TagLimit = Input.TagLimit,
  105. AllowImage = Input.AllowImage,
  106. ImageUploadLimit = Input.ImageUploadLimit,
  107. ImageUploadMaxSize = Input.ImageUploadMaxSize,
  108. AllowMedia = Input.AllowMedia,
  109. MediaUploadLimit = Input.MediaUploadLimit,
  110. AllowFile = Input.AllowFile,
  111. FileUploadLimit = Input.FileUploadLimit,
  112. FileUploadMaxSize = Input.FileUploadMaxSize,
  113. FileUploadExtension = Input.FileUploadExtension
  114. },
  115. null, null, null, null, null, null), ct);
  116. if (result.IsFailure)
  117. {
  118. TempData["ErrorMessages"] = result.Error.Description;
  119. }
  120. else
  121. {
  122. TempData["SuccessMessage"] = "작성 설정이 저장되었습니다.";
  123. }
  124. return Redirect($"/Forum/Board/Meta/Write/{Input.BoardID}{Request.QueryString}");
  125. }
  126. }