Index.cshtml.cs 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. using Application.Abstractions.Messaging;
  2. using Microsoft.AspNetCore.Mvc;
  3. using Microsoft.AspNetCore.Mvc.RazorPages;
  4. using System.ComponentModel;
  5. using System.ComponentModel.DataAnnotations;
  6. namespace Admin.Pages.Channel.Exp;
  7. public class IndexModel(IMediator mediator) : PageModel
  8. {
  9. [BindProperty]
  10. public InputModel Input { get; set; } = new();
  11. public sealed class InputModel
  12. {
  13. [DisplayName("채팅 메시지당 XP")]
  14. [Range(0, 100, ErrorMessage = "{0}은(는) {1}~{2} 사이여야 합니다.")]
  15. public int ChatXpPerMessage { get; set; } = 1;
  16. [DisplayName("후원 POINT당 1 XP 환산 기준")]
  17. [Range(1, 1000000, ErrorMessage = "{0}은(는) {1} 이상이어야 합니다.")]
  18. public int DonationXpPerAmount { get; set; } = 1000;
  19. [DisplayName("방송 세션당 채팅 XP 상한")]
  20. [Range(0, 10000, ErrorMessage = "{0}은(는) {1}~{2} 사이여야 합니다.")]
  21. public int ChatXpSessionLimit { get; set; } = 50;
  22. [DisplayName("XP 적립 최소 글자수")]
  23. [Range(1, 500, ErrorMessage = "{0}은(는) {1}~{2} 사이여야 합니다.")]
  24. public int MinContentLength { get; set; } = 2;
  25. [DisplayName("채팅 쿨다운(초)")]
  26. [Range(0, 60, ErrorMessage = "{0}은(는) {1}~{2} 사이여야 합니다.")]
  27. public int RateLimitSec { get; set; } = 2;
  28. [DisplayName("리더보드 표시 인원")]
  29. [Range(1, 500, ErrorMessage = "{0}은(는) {1}~{2} 사이여야 합니다.")]
  30. public int LeaderboardSize { get; set; } = 50;
  31. [DisplayName("크라운 뱃지 부여 Top N")]
  32. [Range(0, 10, ErrorMessage = "{0}은(는) {1}~{2} 사이여야 합니다.")]
  33. public int CrownTopN { get; set; } = 3;
  34. [DisplayName("리더보드 노출")]
  35. public bool UxShowLeaderboard { get; set; } = true;
  36. [DisplayName("내 XP 뱃지 노출")]
  37. public bool UxShowMyXpBadge { get; set; } = true;
  38. }
  39. public async Task OnGetAsync(CancellationToken ct)
  40. {
  41. var data = await mediator.Send(new GetChannelExpConfig.Query(), ct);
  42. Input = new InputModel
  43. {
  44. ChatXpPerMessage = data.ChatXpPerMessage,
  45. DonationXpPerAmount = data.DonationXpPerAmount,
  46. ChatXpSessionLimit = data.ChatXpSessionLimit,
  47. MinContentLength = data.MinContentLength,
  48. RateLimitSec = data.RateLimitSec,
  49. LeaderboardSize = data.LeaderboardSize,
  50. CrownTopN = data.CrownTopN,
  51. UxShowLeaderboard = data.UxShowLeaderboard,
  52. UxShowMyXpBadge = data.UxShowMyXpBadge
  53. };
  54. }
  55. public async Task<IActionResult> OnPostAsync(CancellationToken ct)
  56. {
  57. if (!ModelState.IsValid)
  58. {
  59. return Page();
  60. }
  61. try
  62. {
  63. await mediator.Send(new UpdateChannelExpConfig.Command(
  64. Input.ChatXpPerMessage,
  65. Input.DonationXpPerAmount,
  66. Input.ChatXpSessionLimit,
  67. Input.MinContentLength,
  68. Input.RateLimitSec,
  69. Input.LeaderboardSize,
  70. Input.CrownTopN,
  71. Input.UxShowLeaderboard,
  72. Input.UxShowMyXpBadge
  73. ), ct);
  74. TempData["SuccessMessage"] = "경험치 설정이 저장되었습니다.";
  75. }
  76. catch (Exception e)
  77. {
  78. TempData["ErrorMessages"] = e.Message;
  79. }
  80. return RedirectToPage("/Channel/Exp/Index");
  81. }
  82. }