Exp.cshtml.cs 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  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 ExpModel(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 EnableExp { get; set; }
  19. public bool ShowExpGuide { get; set; }
  20. // 경험치 지급량
  21. public ushort PostWriteExp { get; set; }
  22. public ushort CommentWriteExp { get; set; }
  23. public ushort FileUploadExp { get; set; }
  24. public short FileDownloadExp { get; set; }
  25. public short OtherPostReadExp { get; set; }
  26. public ushort OtherPostLikeExp { get; set; }
  27. public ushort OtherPostDisLikeExp { get; set; }
  28. public ushort OtherCommentLikeExp { get; set; }
  29. public ushort OtherCommentDisLikeExp { get; set; }
  30. public ushort OwnPostReadExp { get; set; }
  31. public ushort OwnPostLikeExp { get; set; }
  32. public short OwnPostDisLikeExp { get; set; }
  33. public ushort OwnCommentLikeExp { get; set; }
  34. public short OwnCommentDisLikeExp { get; set; }
  35. // 경험치 회수량
  36. public ushort PostWriteUndoExp { get; set; }
  37. public ushort CommentWriteUndoExp { get; set; }
  38. public ushort FileUploadUndoExp { get; set; }
  39. public ushort OtherPostReadUndoExp { get; set; }
  40. public ushort OtherPostLikeUndoExp { get; set; }
  41. public ushort OtherPostDisLikeUndoExp { get; set; }
  42. public ushort OtherCommentLikeUndoExp { get; set; }
  43. public ushort OtherCommentDisLikeUndoExp { get; set; }
  44. public ushort OwnPostReadUndoExp { get; set; }
  45. public ushort OwnPostLikeUndoExp { get; set; }
  46. public ushort OwnPostDisLikeUndoExp { get; set; }
  47. public ushort OwnCommentLikeUndoExp { get; set; }
  48. public ushort OwnCommentDisLikeUndoExp { get; set; }
  49. // 경험치 지급 기한
  50. public ushort PostWriteExpWithinDays { get; set; }
  51. public ushort CommentWriteExpWithinDays { get; set; }
  52. public ushort FileUploadExpWithinDays { get; set; }
  53. public ushort OtherPostReadExpWithinDays { get; set; }
  54. public ushort OtherPostLikeExpWithinDays { get; set; }
  55. public ushort OtherPostDisLikeExpWithinDays { get; set; }
  56. public ushort OtherCommentLikeExpWithinDays { get; set; }
  57. public ushort OtherCommentDisLikeExpWithinDays { get; set; }
  58. public ushort OwnPostReadExpWithinDays { get; set; }
  59. public ushort OwnPostLikeExpWithinDays { get; set; }
  60. public ushort OwnPostDisLikeExpWithinDays { get; set; }
  61. public ushort OwnCommentLikeExpWithinDays { get; set; }
  62. public ushort OwnCommentDisLikeExpWithinDays { get; set; }
  63. }
  64. public async Task OnGetAsync(int id, CancellationToken ct)
  65. {
  66. BoardID = id;
  67. QueryString = Request.QueryString.ToString();
  68. var boards = await mediator.Send(new SearchBoards.Query(null, null, 1, 100), ct);
  69. BoardList = [..boards.List.Select(c => (c.ID, c.Name))];
  70. var meta = await mediator.Send(new GetBoardMeta.Query(id), ct);
  71. Input = new InputModel
  72. {
  73. ID = meta.ID,
  74. BoardID = meta.BoardID,
  75. EnableExp = meta.Exp.EnableExp,
  76. ShowExpGuide = meta.Exp.ShowExpGuide,
  77. PostWriteExp = meta.Exp.PostWriteExp,
  78. CommentWriteExp = meta.Exp.CommentWriteExp,
  79. FileUploadExp = meta.Exp.FileUploadExp,
  80. FileDownloadExp = meta.Exp.FileDownloadExp,
  81. OtherPostReadExp = meta.Exp.OtherPostReadExp,
  82. OtherPostLikeExp = meta.Exp.OtherPostLikeExp,
  83. OtherPostDisLikeExp = meta.Exp.OtherPostDisLikeExp,
  84. OtherCommentLikeExp = meta.Exp.OtherCommentLikeExp,
  85. OtherCommentDisLikeExp = meta.Exp.OtherCommentDisLikeExp,
  86. OwnPostReadExp = meta.Exp.OwnPostReadExp,
  87. OwnPostLikeExp = meta.Exp.OwnPostLikeExp,
  88. OwnPostDisLikeExp = meta.Exp.OwnPostDisLikeExp,
  89. OwnCommentLikeExp = meta.Exp.OwnCommentLikeExp,
  90. OwnCommentDisLikeExp = meta.Exp.OwnCommentDisLikeExp,
  91. PostWriteUndoExp = meta.Exp.PostWriteUndoExp,
  92. CommentWriteUndoExp = meta.Exp.CommentWriteUndoExp,
  93. FileUploadUndoExp = meta.Exp.FileUploadUndoExp,
  94. OtherPostReadUndoExp = meta.Exp.OtherPostReadUndoExp,
  95. OtherPostLikeUndoExp = meta.Exp.OtherPostLikeUndoExp,
  96. OtherPostDisLikeUndoExp = meta.Exp.OtherPostDisLikeUndoExp,
  97. OtherCommentLikeUndoExp = meta.Exp.OtherCommentLikeUndoExp,
  98. OtherCommentDisLikeUndoExp = meta.Exp.OtherCommentDisLikeUndoExp,
  99. OwnPostReadUndoExp = meta.Exp.OwnPostReadUndoExp,
  100. OwnPostLikeUndoExp = meta.Exp.OwnPostLikeUndoExp,
  101. OwnPostDisLikeUndoExp = meta.Exp.OwnPostDisLikeUndoExp,
  102. OwnCommentLikeUndoExp = meta.Exp.OwnCommentLikeUndoExp,
  103. OwnCommentDisLikeUndoExp = meta.Exp.OwnCommentDisLikeUndoExp,
  104. PostWriteExpWithinDays = meta.Exp.PostWriteExpWithinDays,
  105. CommentWriteExpWithinDays = meta.Exp.CommentWriteExpWithinDays,
  106. FileUploadExpWithinDays = meta.Exp.FileUploadExpWithinDays,
  107. OtherPostReadExpWithinDays = meta.Exp.OtherPostReadExpWithinDays,
  108. OtherPostLikeExpWithinDays = meta.Exp.OtherPostLikeExpWithinDays,
  109. OtherPostDisLikeExpWithinDays = meta.Exp.OtherPostDisLikeExpWithinDays,
  110. OtherCommentLikeExpWithinDays = meta.Exp.OtherCommentLikeExpWithinDays,
  111. OtherCommentDisLikeExpWithinDays = meta.Exp.OtherCommentDisLikeExpWithinDays,
  112. OwnPostReadExpWithinDays = meta.Exp.OwnPostReadExpWithinDays,
  113. OwnPostLikeExpWithinDays = meta.Exp.OwnPostLikeExpWithinDays,
  114. OwnPostDisLikeExpWithinDays = meta.Exp.OwnPostDisLikeExpWithinDays,
  115. OwnCommentLikeExpWithinDays = meta.Exp.OwnCommentLikeExpWithinDays,
  116. OwnCommentDisLikeExpWithinDays = meta.Exp.OwnCommentDisLikeExpWithinDays
  117. };
  118. }
  119. public async Task<IActionResult> OnPostAsync(CancellationToken ct)
  120. {
  121. try
  122. {
  123. if (!ModelState.IsValid)
  124. {
  125. throw new Exception(ModelState.GetErrorMessages());
  126. }
  127. await mediator.Send(new UpdateBoardMeta.Command(
  128. Input.ID,
  129. Input.BoardID,
  130. null,
  131. null,
  132. null,
  133. null,
  134. null,
  135. null,
  136. null,
  137. null,
  138. new BoardMetaExp
  139. {
  140. EnableExp = Input.EnableExp,
  141. ShowExpGuide = Input.ShowExpGuide,
  142. PostWriteExp = Input.PostWriteExp,
  143. CommentWriteExp = Input.CommentWriteExp,
  144. FileUploadExp = Input.FileUploadExp,
  145. FileDownloadExp = Input.FileDownloadExp,
  146. OtherPostReadExp = Input.OtherPostReadExp,
  147. OtherPostLikeExp = Input.OtherPostLikeExp,
  148. OtherPostDisLikeExp = Input.OtherPostDisLikeExp,
  149. OtherCommentLikeExp = Input.OtherCommentLikeExp,
  150. OtherCommentDisLikeExp = Input.OtherCommentDisLikeExp,
  151. OwnPostReadExp = Input.OwnPostReadExp,
  152. OwnPostLikeExp = Input.OwnPostLikeExp,
  153. OwnPostDisLikeExp = Input.OwnPostDisLikeExp,
  154. OwnCommentLikeExp = Input.OwnCommentLikeExp,
  155. OwnCommentDisLikeExp = Input.OwnCommentDisLikeExp,
  156. PostWriteUndoExp = Input.PostWriteUndoExp,
  157. CommentWriteUndoExp = Input.CommentWriteUndoExp,
  158. FileUploadUndoExp = Input.FileUploadUndoExp,
  159. OtherPostReadUndoExp = Input.OtherPostReadUndoExp,
  160. OtherPostLikeUndoExp = Input.OtherPostLikeUndoExp,
  161. OtherPostDisLikeUndoExp = Input.OtherPostDisLikeUndoExp,
  162. OtherCommentLikeUndoExp = Input.OtherCommentLikeUndoExp,
  163. OtherCommentDisLikeUndoExp = Input.OtherCommentDisLikeUndoExp,
  164. OwnPostReadUndoExp = Input.OwnPostReadUndoExp,
  165. OwnPostLikeUndoExp = Input.OwnPostLikeUndoExp,
  166. OwnPostDisLikeUndoExp = Input.OwnPostDisLikeUndoExp,
  167. OwnCommentLikeUndoExp = Input.OwnCommentLikeUndoExp,
  168. OwnCommentDisLikeUndoExp = Input.OwnCommentDisLikeUndoExp,
  169. PostWriteExpWithinDays = Input.PostWriteExpWithinDays,
  170. CommentWriteExpWithinDays = Input.CommentWriteExpWithinDays,
  171. FileUploadExpWithinDays = Input.FileUploadExpWithinDays,
  172. OtherPostReadExpWithinDays = Input.OtherPostReadExpWithinDays,
  173. OtherPostLikeExpWithinDays = Input.OtherPostLikeExpWithinDays,
  174. OtherPostDisLikeExpWithinDays = Input.OtherPostDisLikeExpWithinDays,
  175. OtherCommentLikeExpWithinDays = Input.OtherCommentLikeExpWithinDays,
  176. OtherCommentDisLikeExpWithinDays = Input.OtherCommentDisLikeExpWithinDays,
  177. OwnPostReadExpWithinDays = Input.OwnPostReadExpWithinDays,
  178. OwnPostLikeExpWithinDays = Input.OwnPostLikeExpWithinDays,
  179. OwnPostDisLikeExpWithinDays = Input.OwnPostDisLikeExpWithinDays,
  180. OwnCommentLikeExpWithinDays = Input.OwnCommentLikeExpWithinDays,
  181. OwnCommentDisLikeExpWithinDays = Input.OwnCommentDisLikeExpWithinDays
  182. }), ct);
  183. TempData["SuccessMessage"] = "경험치 설정이 저장되었습니다.";
  184. }
  185. catch (Exception e)
  186. {
  187. TempData["ErrorMessages"] = e.Message;
  188. }
  189. return Redirect($"/Forum/Board/Meta/Exp/{Input.BoardID}{Request.QueryString}");
  190. }
  191. }