General.cshtml.cs 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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 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 meta = await mediator.Send(new GetBoardMeta.Query(id), ct);
  33. Input = new InputModel
  34. {
  35. ID = meta.ID,
  36. BoardID = meta.BoardID,
  37. AllowUpdateProtection = meta.General.AllowUpdateProtection,
  38. UpdateProtectionDays = meta.General.UpdateProtectionDays,
  39. AllowDeleteProtection = meta.General.AllowDeleteProtection,
  40. DeleteProtectionDays = meta.General.DeleteProtectionDays,
  41. EnableFileDownLog = meta.General.EnableFileDownLog,
  42. EnableLinkClickLog = meta.General.EnableLinkClickLog,
  43. EnablePostUpdateLog = meta.General.EnablePostUpdateLog
  44. };
  45. }
  46. public async Task<IActionResult> OnPostAsync(CancellationToken ct)
  47. {
  48. try
  49. {
  50. if (!ModelState.IsValid)
  51. {
  52. throw new Exception(ModelState.GetErrorMessages());
  53. }
  54. await mediator.Send(new UpdateBoardMeta.Command(
  55. Input.ID,
  56. Input.BoardID,
  57. null,
  58. null,
  59. null,
  60. null,
  61. new BoardMetaGeneral
  62. {
  63. AllowUpdateProtection = Input.AllowUpdateProtection,
  64. UpdateProtectionDays = Input.UpdateProtectionDays,
  65. AllowDeleteProtection = Input.AllowDeleteProtection,
  66. DeleteProtectionDays = Input.DeleteProtectionDays,
  67. EnableFileDownLog = Input.EnableFileDownLog,
  68. EnableLinkClickLog = Input.EnableLinkClickLog,
  69. EnablePostUpdateLog = Input.EnablePostUpdateLog
  70. },
  71. null,
  72. null,
  73. null,
  74. null
  75. ), ct);
  76. TempData["SuccessMessage"] = "일반 설정이 저장되었습니다.";
  77. }
  78. catch (Exception e)
  79. {
  80. TempData["ErrorMessages"] = e.Message;
  81. }
  82. return Redirect($"/Forum/Board/Meta/General/{Input.BoardID}{Request.QueryString}");
  83. }
  84. }