General.cshtml.cs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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 GeneralModel(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 AllowUpdateProtection { get; set; }
  19. public ushort UpdateProtectionDays { get; set; }
  20. public bool AllowDeleteProtection { get; set; }
  21. public ushort DeleteProtectionDays { get; set; }
  22. public bool EnableFileDownLog { get; set; }
  23. public bool EnableLinkClickLog { get; set; }
  24. public bool EnablePostUpdateLog { get; set; }
  25. }
  26. public async Task OnGetAsync(int id, CancellationToken ct)
  27. {
  28. BoardID = id;
  29. QueryString = Request.QueryString.ToString();
  30. var boards = await mediator.Send(new SearchBoards.Query(null, null, 1, 100), ct);
  31. BoardList = [..boards.List.Select(c => (c.ID, c.Name))];
  32. var metaResult = await mediator.Send(new GetBoardMeta.Query(id), ct);
  33. if (metaResult.IsFailure)
  34. {
  35. TempData["ErrorMessages"] = metaResult.Error.Description;
  36. return;
  37. }
  38. var meta = metaResult.Value;
  39. Input = new InputModel
  40. {
  41. ID = meta.ID,
  42. BoardID = meta.BoardID,
  43. AllowUpdateProtection = meta.General.AllowUpdateProtection,
  44. UpdateProtectionDays = meta.General.UpdateProtectionDays,
  45. AllowDeleteProtection = meta.General.AllowDeleteProtection,
  46. DeleteProtectionDays = meta.General.DeleteProtectionDays,
  47. EnableFileDownLog = meta.General.EnableFileDownLog,
  48. EnableLinkClickLog = meta.General.EnableLinkClickLog,
  49. EnablePostUpdateLog = meta.General.EnablePostUpdateLog
  50. };
  51. }
  52. public async Task<IActionResult> OnPostAsync(CancellationToken ct)
  53. {
  54. if (!ModelState.IsValid)
  55. {
  56. TempData["ErrorMessages"] = ModelState.GetErrorMessages();
  57. return Redirect($"/Forum/Board/Meta/General/{Input.BoardID}{Request.QueryString}");
  58. }
  59. var result = await mediator.Send(new UpdateBoardMeta.Command(
  60. Input.ID,
  61. Input.BoardID,
  62. null,
  63. null,
  64. null,
  65. null,
  66. new BoardMetaGeneral
  67. {
  68. AllowUpdateProtection = Input.AllowUpdateProtection,
  69. UpdateProtectionDays = Input.UpdateProtectionDays,
  70. AllowDeleteProtection = Input.AllowDeleteProtection,
  71. DeleteProtectionDays = Input.DeleteProtectionDays,
  72. EnableFileDownLog = Input.EnableFileDownLog,
  73. EnableLinkClickLog = Input.EnableLinkClickLog,
  74. EnablePostUpdateLog = Input.EnablePostUpdateLog
  75. },
  76. null,
  77. null,
  78. null,
  79. null
  80. ), ct);
  81. if (result.IsFailure)
  82. {
  83. TempData["ErrorMessages"] = result.Error.Description;
  84. }
  85. else
  86. {
  87. TempData["SuccessMessage"] = "일반 설정이 저장되었습니다.";
  88. }
  89. return Redirect($"/Forum/Board/Meta/General/{Input.BoardID}{Request.QueryString}");
  90. }
  91. }