View.cshtml.cs 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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 ViewMetaModel(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 AllowBookmark { get; set; }
  19. public bool AllowLike { get; set; }
  20. public bool AllowDislike { get; set; }
  21. public bool AllowPrint { get; set; }
  22. public bool AllowSnsShare { get; set; }
  23. public bool AllowPrevNextBotton { get; set; }
  24. public bool AllowBlame { get; set; }
  25. public ushort BlameHideCount { get; set; }
  26. public bool AllowContentLinkTargetBlank { get; set; }
  27. public bool AllowPostUrlCopy { get; set; }
  28. public bool AllowPostUrlQrCode { get; set; }
  29. public bool ShowMemberThumb { get; set; }
  30. public bool ShowMemberIcon { get; set; }
  31. public bool ShowMemberRegDate { get; set; }
  32. public bool ShowMemberSummary { get; set; }
  33. }
  34. public async Task OnGetAsync(int id, CancellationToken ct)
  35. {
  36. BoardID = id;
  37. QueryString = Request.QueryString.ToString();
  38. var boards = await mediator.Send(new SearchBoards.Query(null, null, 1, 100), ct);
  39. BoardList = [..boards.List.Select(c => (c.ID, c.Name))];
  40. var meta = await mediator.Send(new GetBoardMeta.Query(id), ct);
  41. Input = new InputModel
  42. {
  43. ID = meta.ID,
  44. BoardID = meta.BoardID,
  45. AllowBookmark = meta.View.AllowBookmark,
  46. AllowLike = meta.View.AllowLike,
  47. AllowDislike = meta.View.AllowDislike,
  48. AllowPrint = meta.View.AllowPrint,
  49. AllowSnsShare = meta.View.AllowSnsShare,
  50. AllowPrevNextBotton = meta.View.AllowPrevNextBotton,
  51. AllowBlame = meta.View.AllowBlame,
  52. BlameHideCount = meta.View.BlameHideCount,
  53. AllowContentLinkTargetBlank = meta.View.AllowContentLinkTargetBlank,
  54. AllowPostUrlCopy = meta.View.AllowPostUrlCopy,
  55. AllowPostUrlQrCode = meta.View.AllowPostUrlQrCode,
  56. ShowMemberThumb = meta.View.ShowMemberThumb,
  57. ShowMemberIcon = meta.View.ShowMemberIcon,
  58. ShowMemberRegDate = meta.View.ShowMemberRegDate,
  59. ShowMemberSummary = meta.View.ShowMemberSummary
  60. };
  61. }
  62. public async Task<IActionResult> OnPostAsync(CancellationToken ct)
  63. {
  64. try
  65. {
  66. if (!ModelState.IsValid)
  67. {
  68. throw new Exception(ModelState.GetErrorMessages());
  69. }
  70. await mediator.Send(new UpdateBoardMeta.Command(
  71. Input.ID,
  72. Input.BoardID,
  73. null,
  74. new BoardMetaView
  75. {
  76. AllowBookmark = Input.AllowBookmark,
  77. AllowLike = Input.AllowLike,
  78. AllowDislike = Input.AllowDislike,
  79. AllowPrint = Input.AllowPrint,
  80. AllowSnsShare = Input.AllowSnsShare,
  81. AllowPrevNextBotton = Input.AllowPrevNextBotton,
  82. AllowBlame = Input.AllowBlame,
  83. BlameHideCount = Input.BlameHideCount,
  84. AllowContentLinkTargetBlank = Input.AllowContentLinkTargetBlank,
  85. AllowPostUrlCopy = Input.AllowPostUrlCopy,
  86. AllowPostUrlQrCode = Input.AllowPostUrlQrCode,
  87. ShowMemberThumb = Input.ShowMemberThumb,
  88. ShowMemberIcon = Input.ShowMemberIcon,
  89. ShowMemberRegDate = Input.ShowMemberRegDate,
  90. ShowMemberSummary = Input.ShowMemberSummary
  91. },
  92. null, null, null, null, null, null, null), ct);
  93. TempData["SuccessMessage"] = "열람 설정이 저장되었습니다.";
  94. }
  95. catch (Exception e)
  96. {
  97. TempData["ErrorMessages"] = e.Message;
  98. }
  99. return Redirect($"/Forum/Board/Meta/View/{Input.BoardID}{Request.QueryString}");
  100. }
  101. }