List.cshtml.cs 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. using Domain.Entities.Forum.Boards;
  2. using Domain.Entities.Forum.ValueObject;
  3. using SharedKernel.Extensions;
  4. using MediatR;
  5. using Microsoft.AspNetCore.Mvc;
  6. using Microsoft.AspNetCore.Mvc.RazorPages;
  7. namespace Admin.Pages.Forum.Board.Meta;
  8. public class ListModel(IMediator mediator) : PageModel
  9. {
  10. public int BoardID { get; set; }
  11. public List<(int ID, string Name)> BoardList { get; set; } = [];
  12. public string? QueryString { get; set; }
  13. [BindProperty]
  14. public InputModel Input { get; set; } = new();
  15. public sealed class InputModel
  16. {
  17. public int ID { get; set; }
  18. public int BoardID { get; set; }
  19. public bool ShowHeader { get; set; }
  20. public string? HeaderContent { get; set; }
  21. public bool ShowFooter { get; set; }
  22. public string? FooterContent { get; set; }
  23. public BoardLayout? Layout { get; set; }
  24. public BoardSort? Sort { get; set; }
  25. public byte PerPage { get; set; }
  26. public bool AlwaysShowWriteButton { get; set; }
  27. public bool ShowFooterListView { get; set; }
  28. public bool IsNewIcon { get; set; }
  29. public bool IsHotIcon { get; set; }
  30. public bool ExceptNotice { get; set; }
  31. public bool ExceptSpeaker { get; set; }
  32. }
  33. public async Task OnGetAsync(int id, CancellationToken ct)
  34. {
  35. BoardID = id;
  36. QueryString = Request.QueryString.ToString();
  37. var boards = await mediator.Send(new SearchBoards.Query(null, null, 1, 100), ct);
  38. BoardList = [..boards.List.Select(c => (c.ID, c.Name))];
  39. var meta = await mediator.Send(new GetBoardMeta.Query(id), ct);
  40. Input = new InputModel
  41. {
  42. ID = meta.ID,
  43. BoardID = meta.BoardID,
  44. ShowHeader = meta.List.ShowHeader,
  45. HeaderContent = meta.List.HeaderContent,
  46. ShowFooter = meta.List.ShowFooter,
  47. FooterContent = meta.List.FooterContent,
  48. Layout = meta.List.Layout,
  49. Sort = meta.List.Sort,
  50. PerPage = meta.List.PerPage,
  51. AlwaysShowWriteButton = meta.List.AlwaysShowWriteButton,
  52. ShowFooterListView = meta.List.ShowFooterListView,
  53. IsNewIcon = meta.List.IsNewIcon,
  54. IsHotIcon = meta.List.IsHotIcon,
  55. ExceptNotice = meta.List.ExceptNotice,
  56. ExceptSpeaker = meta.List.ExceptSpeaker
  57. };
  58. }
  59. public async Task<IActionResult> OnPostAsync(CancellationToken ct)
  60. {
  61. try
  62. {
  63. if (!ModelState.IsValid)
  64. {
  65. throw new Exception(ModelState.GetErrorMessages());
  66. }
  67. await mediator.Send(new UpdateBoardMeta.Command(
  68. Input.ID,
  69. Input.BoardID,
  70. new BoardMetaList
  71. {
  72. ShowHeader = Input.ShowHeader,
  73. HeaderContent = Input.HeaderContent,
  74. ShowFooter = Input.ShowFooter,
  75. FooterContent = Input.FooterContent,
  76. Layout = Input.Layout,
  77. Sort = Input.Sort,
  78. PerPage = Input.PerPage,
  79. AlwaysShowWriteButton = Input.AlwaysShowWriteButton,
  80. ShowFooterListView = Input.ShowFooterListView,
  81. IsNewIcon = Input.IsNewIcon,
  82. IsHotIcon = Input.IsHotIcon,
  83. ExceptNotice = Input.ExceptNotice,
  84. ExceptSpeaker = Input.ExceptSpeaker
  85. },
  86. null,
  87. null,
  88. null,
  89. null,
  90. null,
  91. null,
  92. null,
  93. null
  94. ), ct);
  95. TempData["SuccessMessage"] = "목록 설정이 저장되었습니다.";
  96. }
  97. catch (Exception e)
  98. {
  99. TempData["ErrorMessages"] = e.Message;
  100. }
  101. return Redirect($"/Forum/Board/Meta/List/{Input.BoardID}{Request.QueryString}");
  102. }
  103. }