Comment.cshtml.cs 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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 CommentModel(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 EnableComment { get; set; }
  19. public ushort PerPage { get; set; }
  20. public bool AllowLike { get; set; }
  21. public bool AllowDisLike { get; set; }
  22. public bool ShowMemberThumb { get; set; }
  23. public bool ShowMemberIcon { get; set; }
  24. public string? ContentPlaceholder { get; set; }
  25. public ushort MinContentLength { get; set; }
  26. public ushort MaxContentLength { get; set; }
  27. public bool EnableEditor { get; set; }
  28. public bool AllowSecret { get; set; }
  29. public ushort BlameHideCount { get; set; }
  30. public bool AllowUpdateProtection { get; set; }
  31. public ushort UpdateProtectionDays { get; set; }
  32. public bool AllowDeleteProtection { get; set; }
  33. public ushort DeleteProtectionDays { get; set; }
  34. public bool EnableCommentUpdateLog { get; set; }
  35. }
  36. public async Task OnGetAsync(int id, CancellationToken ct)
  37. {
  38. BoardID = id;
  39. QueryString = Request.QueryString.ToString();
  40. var boards = await mediator.Send(new SearchBoards.Query(null, null, 1, 100), ct);
  41. BoardList = [..boards.List.Select(c => (c.ID, c.Name))];
  42. var meta = await mediator.Send(new GetBoardMeta.Query(id), ct);
  43. Input = new InputModel
  44. {
  45. ID = meta.ID,
  46. BoardID = meta.BoardID,
  47. EnableComment = meta.Comment.EnableComment,
  48. PerPage = meta.Comment.PerPage,
  49. AllowLike = meta.Comment.AllowLike,
  50. AllowDisLike = meta.Comment.AllowDisLike,
  51. ShowMemberThumb = meta.Comment.ShowMemberThumb,
  52. ShowMemberIcon = meta.Comment.ShowMemberIcon,
  53. ContentPlaceholder = meta.Comment.ContentPlaceholder,
  54. MinContentLength = meta.Comment.MinContentLength,
  55. MaxContentLength = meta.Comment.MaxContentLength,
  56. EnableEditor = meta.Comment.EnableEditor,
  57. AllowSecret = meta.Comment.AllowSecret,
  58. BlameHideCount = meta.Comment.BlameHideCount,
  59. AllowUpdateProtection = meta.Comment.AllowUpdateProtection,
  60. UpdateProtectionDays = meta.Comment.UpdateProtectionDays,
  61. AllowDeleteProtection = meta.Comment.AllowDeleteProtection,
  62. DeleteProtectionDays = meta.Comment.DeleteProtectionDays,
  63. EnableCommentUpdateLog = meta.Comment.EnableCommentUpdateLog
  64. };
  65. }
  66. public async Task<IActionResult> OnPostAsync(CancellationToken ct)
  67. {
  68. try
  69. {
  70. if (!ModelState.IsValid)
  71. {
  72. throw new Exception(ModelState.GetErrorMessages());
  73. }
  74. await mediator.Send(new UpdateBoardMeta.Command(
  75. Input.ID,
  76. Input.BoardID,
  77. null,
  78. null,
  79. null,
  80. new BoardMetaComment
  81. {
  82. EnableComment = Input.EnableComment,
  83. PerPage = Input.PerPage,
  84. AllowLike = Input.AllowLike,
  85. AllowDisLike = Input.AllowDisLike,
  86. ShowMemberThumb = Input.ShowMemberThumb,
  87. ShowMemberIcon = Input.ShowMemberIcon,
  88. ContentPlaceholder = Input.ContentPlaceholder,
  89. MinContentLength = Input.MinContentLength,
  90. MaxContentLength = Input.MaxContentLength,
  91. EnableEditor = Input.EnableEditor,
  92. AllowSecret = Input.AllowSecret,
  93. BlameHideCount = Input.BlameHideCount,
  94. AllowUpdateProtection = Input.AllowUpdateProtection,
  95. UpdateProtectionDays = Input.UpdateProtectionDays,
  96. AllowDeleteProtection = Input.AllowDeleteProtection,
  97. DeleteProtectionDays = Input.DeleteProtectionDays,
  98. EnableCommentUpdateLog = Input.EnableCommentUpdateLog
  99. },
  100. null,
  101. null,
  102. null,
  103. null,
  104. null
  105. ), ct);
  106. TempData["SuccessMessage"] = "댓글 설정이 저장되었습니다.";
  107. }
  108. catch (Exception e)
  109. {
  110. TempData["ErrorMessages"] = e.Message;
  111. }
  112. return Redirect($"/Forum/Board/Meta/Comment/{Input.BoardID}{Request.QueryString}");
  113. }
  114. }