Exp.cshtml.cs 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  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 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 metaResult = await mediator.Send(new GetBoardMeta.Query(id), ct);
  71. if (metaResult.IsFailure)
  72. {
  73. TempData["ErrorMessages"] = metaResult.Error.Description;
  74. return;
  75. }
  76. var meta = metaResult.Value;
  77. Input = new InputModel
  78. {
  79. ID = meta.ID,
  80. BoardID = meta.BoardID,
  81. EnableExp = meta.Exp.EnableExp,
  82. ShowExpGuide = meta.Exp.ShowExpGuide,
  83. PostWriteExp = meta.Exp.PostWriteExp,
  84. CommentWriteExp = meta.Exp.CommentWriteExp,
  85. FileUploadExp = meta.Exp.FileUploadExp,
  86. FileDownloadExp = meta.Exp.FileDownloadExp,
  87. OtherPostReadExp = meta.Exp.OtherPostReadExp,
  88. OtherPostLikeExp = meta.Exp.OtherPostLikeExp,
  89. OtherPostDisLikeExp = meta.Exp.OtherPostDisLikeExp,
  90. OtherCommentLikeExp = meta.Exp.OtherCommentLikeExp,
  91. OtherCommentDisLikeExp = meta.Exp.OtherCommentDisLikeExp,
  92. OwnPostReadExp = meta.Exp.OwnPostReadExp,
  93. OwnPostLikeExp = meta.Exp.OwnPostLikeExp,
  94. OwnPostDisLikeExp = meta.Exp.OwnPostDisLikeExp,
  95. OwnCommentLikeExp = meta.Exp.OwnCommentLikeExp,
  96. OwnCommentDisLikeExp = meta.Exp.OwnCommentDisLikeExp,
  97. PostWriteUndoExp = meta.Exp.PostWriteUndoExp,
  98. CommentWriteUndoExp = meta.Exp.CommentWriteUndoExp,
  99. FileUploadUndoExp = meta.Exp.FileUploadUndoExp,
  100. OtherPostReadUndoExp = meta.Exp.OtherPostReadUndoExp,
  101. OtherPostLikeUndoExp = meta.Exp.OtherPostLikeUndoExp,
  102. OtherPostDisLikeUndoExp = meta.Exp.OtherPostDisLikeUndoExp,
  103. OtherCommentLikeUndoExp = meta.Exp.OtherCommentLikeUndoExp,
  104. OtherCommentDisLikeUndoExp = meta.Exp.OtherCommentDisLikeUndoExp,
  105. OwnPostReadUndoExp = meta.Exp.OwnPostReadUndoExp,
  106. OwnPostLikeUndoExp = meta.Exp.OwnPostLikeUndoExp,
  107. OwnPostDisLikeUndoExp = meta.Exp.OwnPostDisLikeUndoExp,
  108. OwnCommentLikeUndoExp = meta.Exp.OwnCommentLikeUndoExp,
  109. OwnCommentDisLikeUndoExp = meta.Exp.OwnCommentDisLikeUndoExp,
  110. PostWriteExpWithinDays = meta.Exp.PostWriteExpWithinDays,
  111. CommentWriteExpWithinDays = meta.Exp.CommentWriteExpWithinDays,
  112. FileUploadExpWithinDays = meta.Exp.FileUploadExpWithinDays,
  113. OtherPostReadExpWithinDays = meta.Exp.OtherPostReadExpWithinDays,
  114. OtherPostLikeExpWithinDays = meta.Exp.OtherPostLikeExpWithinDays,
  115. OtherPostDisLikeExpWithinDays = meta.Exp.OtherPostDisLikeExpWithinDays,
  116. OtherCommentLikeExpWithinDays = meta.Exp.OtherCommentLikeExpWithinDays,
  117. OtherCommentDisLikeExpWithinDays = meta.Exp.OtherCommentDisLikeExpWithinDays,
  118. OwnPostReadExpWithinDays = meta.Exp.OwnPostReadExpWithinDays,
  119. OwnPostLikeExpWithinDays = meta.Exp.OwnPostLikeExpWithinDays,
  120. OwnPostDisLikeExpWithinDays = meta.Exp.OwnPostDisLikeExpWithinDays,
  121. OwnCommentLikeExpWithinDays = meta.Exp.OwnCommentLikeExpWithinDays,
  122. OwnCommentDisLikeExpWithinDays = meta.Exp.OwnCommentDisLikeExpWithinDays
  123. };
  124. }
  125. public async Task<IActionResult> OnPostAsync(CancellationToken ct)
  126. {
  127. if (!ModelState.IsValid)
  128. {
  129. TempData["ErrorMessages"] = ModelState.GetErrorMessages();
  130. return Redirect($"/Forum/Board/Meta/Exp/{Input.BoardID}{Request.QueryString}");
  131. }
  132. var result = await mediator.Send(new UpdateBoardMeta.Command(
  133. Input.ID,
  134. Input.BoardID,
  135. null,
  136. null,
  137. null,
  138. null,
  139. null,
  140. null,
  141. null,
  142. null,
  143. new BoardMetaExp
  144. {
  145. EnableExp = Input.EnableExp,
  146. ShowExpGuide = Input.ShowExpGuide,
  147. PostWriteExp = Input.PostWriteExp,
  148. CommentWriteExp = Input.CommentWriteExp,
  149. FileUploadExp = Input.FileUploadExp,
  150. FileDownloadExp = Input.FileDownloadExp,
  151. OtherPostReadExp = Input.OtherPostReadExp,
  152. OtherPostLikeExp = Input.OtherPostLikeExp,
  153. OtherPostDisLikeExp = Input.OtherPostDisLikeExp,
  154. OtherCommentLikeExp = Input.OtherCommentLikeExp,
  155. OtherCommentDisLikeExp = Input.OtherCommentDisLikeExp,
  156. OwnPostReadExp = Input.OwnPostReadExp,
  157. OwnPostLikeExp = Input.OwnPostLikeExp,
  158. OwnPostDisLikeExp = Input.OwnPostDisLikeExp,
  159. OwnCommentLikeExp = Input.OwnCommentLikeExp,
  160. OwnCommentDisLikeExp = Input.OwnCommentDisLikeExp,
  161. PostWriteUndoExp = Input.PostWriteUndoExp,
  162. CommentWriteUndoExp = Input.CommentWriteUndoExp,
  163. FileUploadUndoExp = Input.FileUploadUndoExp,
  164. OtherPostReadUndoExp = Input.OtherPostReadUndoExp,
  165. OtherPostLikeUndoExp = Input.OtherPostLikeUndoExp,
  166. OtherPostDisLikeUndoExp = Input.OtherPostDisLikeUndoExp,
  167. OtherCommentLikeUndoExp = Input.OtherCommentLikeUndoExp,
  168. OtherCommentDisLikeUndoExp = Input.OtherCommentDisLikeUndoExp,
  169. OwnPostReadUndoExp = Input.OwnPostReadUndoExp,
  170. OwnPostLikeUndoExp = Input.OwnPostLikeUndoExp,
  171. OwnPostDisLikeUndoExp = Input.OwnPostDisLikeUndoExp,
  172. OwnCommentLikeUndoExp = Input.OwnCommentLikeUndoExp,
  173. OwnCommentDisLikeUndoExp = Input.OwnCommentDisLikeUndoExp,
  174. PostWriteExpWithinDays = Input.PostWriteExpWithinDays,
  175. CommentWriteExpWithinDays = Input.CommentWriteExpWithinDays,
  176. FileUploadExpWithinDays = Input.FileUploadExpWithinDays,
  177. OtherPostReadExpWithinDays = Input.OtherPostReadExpWithinDays,
  178. OtherPostLikeExpWithinDays = Input.OtherPostLikeExpWithinDays,
  179. OtherPostDisLikeExpWithinDays = Input.OtherPostDisLikeExpWithinDays,
  180. OtherCommentLikeExpWithinDays = Input.OtherCommentLikeExpWithinDays,
  181. OtherCommentDisLikeExpWithinDays = Input.OtherCommentDisLikeExpWithinDays,
  182. OwnPostReadExpWithinDays = Input.OwnPostReadExpWithinDays,
  183. OwnPostLikeExpWithinDays = Input.OwnPostLikeExpWithinDays,
  184. OwnPostDisLikeExpWithinDays = Input.OwnPostDisLikeExpWithinDays,
  185. OwnCommentLikeExpWithinDays = Input.OwnCommentLikeExpWithinDays,
  186. OwnCommentDisLikeExpWithinDays = Input.OwnCommentDisLikeExpWithinDays
  187. }), ct);
  188. if (result.IsFailure)
  189. {
  190. TempData["ErrorMessages"] = result.Error.Description;
  191. }
  192. else
  193. {
  194. TempData["SuccessMessage"] = "경험치 설정이 저장되었습니다.";
  195. }
  196. return Redirect($"/Forum/Board/Meta/Exp/{Input.BoardID}{Request.QueryString}");
  197. }
  198. }