Comment.cshtml.cs 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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 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 metaResult = await mediator.Send(new GetBoardMeta.Query(id), ct);
  43. if (metaResult.IsFailure)
  44. {
  45. TempData["ErrorMessages"] = metaResult.Error.Description;
  46. return;
  47. }
  48. var meta = metaResult.Value;
  49. Input = new InputModel
  50. {
  51. ID = meta.ID,
  52. BoardID = meta.BoardID,
  53. EnableComment = meta.Comment.EnableComment,
  54. PerPage = meta.Comment.PerPage,
  55. AllowLike = meta.Comment.AllowLike,
  56. AllowDisLike = meta.Comment.AllowDisLike,
  57. ShowMemberThumb = meta.Comment.ShowMemberThumb,
  58. ShowMemberIcon = meta.Comment.ShowMemberIcon,
  59. ContentPlaceholder = meta.Comment.ContentPlaceholder,
  60. MinContentLength = meta.Comment.MinContentLength,
  61. MaxContentLength = meta.Comment.MaxContentLength,
  62. EnableEditor = meta.Comment.EnableEditor,
  63. AllowSecret = meta.Comment.AllowSecret,
  64. BlameHideCount = meta.Comment.BlameHideCount,
  65. AllowUpdateProtection = meta.Comment.AllowUpdateProtection,
  66. UpdateProtectionDays = meta.Comment.UpdateProtectionDays,
  67. AllowDeleteProtection = meta.Comment.AllowDeleteProtection,
  68. DeleteProtectionDays = meta.Comment.DeleteProtectionDays,
  69. EnableCommentUpdateLog = meta.Comment.EnableCommentUpdateLog
  70. };
  71. }
  72. public async Task<IActionResult> OnPostAsync(CancellationToken ct)
  73. {
  74. if (!ModelState.IsValid)
  75. {
  76. TempData["ErrorMessages"] = ModelState.GetErrorMessages();
  77. return Redirect($"/Forum/Board/Meta/Comment/{Input.BoardID}{Request.QueryString}");
  78. }
  79. var result = await mediator.Send(new UpdateBoardMeta.Command(
  80. Input.ID,
  81. Input.BoardID,
  82. null,
  83. null,
  84. null,
  85. new BoardMetaComment
  86. {
  87. EnableComment = Input.EnableComment,
  88. PerPage = Input.PerPage,
  89. AllowLike = Input.AllowLike,
  90. AllowDisLike = Input.AllowDisLike,
  91. ShowMemberThumb = Input.ShowMemberThumb,
  92. ShowMemberIcon = Input.ShowMemberIcon,
  93. ContentPlaceholder = Input.ContentPlaceholder,
  94. MinContentLength = Input.MinContentLength,
  95. MaxContentLength = Input.MaxContentLength,
  96. EnableEditor = Input.EnableEditor,
  97. AllowSecret = Input.AllowSecret,
  98. BlameHideCount = Input.BlameHideCount,
  99. AllowUpdateProtection = Input.AllowUpdateProtection,
  100. UpdateProtectionDays = Input.UpdateProtectionDays,
  101. AllowDeleteProtection = Input.AllowDeleteProtection,
  102. DeleteProtectionDays = Input.DeleteProtectionDays,
  103. EnableCommentUpdateLog = Input.EnableCommentUpdateLog
  104. },
  105. null,
  106. null,
  107. null,
  108. null,
  109. null
  110. ), ct);
  111. if (result.IsFailure)
  112. {
  113. TempData["ErrorMessages"] = result.Error.Description;
  114. }
  115. else
  116. {
  117. TempData["SuccessMessage"] = "댓글 설정이 저장되었습니다.";
  118. }
  119. return Redirect($"/Forum/Board/Meta/Comment/{Input.BoardID}{Request.QueryString}");
  120. }
  121. }