View.cshtml.cs 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. using SharedKernel.Extensions;
  2. using Domain.Entities.Wallets.ValueObject;
  3. using Application.Abstractions.Messaging;
  4. using Microsoft.AspNetCore.Mvc;
  5. using Microsoft.AspNetCore.Mvc.RazorPages;
  6. namespace Admin.Pages.Member.Wallet.Transactions;
  7. public class ViewModel(IMediator mediator) : PageModel
  8. {
  9. public TransactionDetail Detail { get; set; } = new();
  10. public sealed class TransactionDetail
  11. {
  12. public int ID { get; set; }
  13. public Guid WalletKey { get; set; }
  14. public int WalletID { get; set; }
  15. public int MemberID { get; set; }
  16. public string MemberEmail { get; set; } = default!;
  17. public string? MemberName { get; set; }
  18. public string WalletBalance { get; set; } = "0";
  19. public string WalletDonationBalance { get; set; } = "0";
  20. public string TxType { get; set; } = default!;
  21. public string BalanceType { get; set; } = default!;
  22. public string Amount { get; set; } = "0";
  23. public string BalanceAfter { get; set; } = "0";
  24. public string? Reason { get; set; }
  25. public string? RefID { get; set; }
  26. public string? UserID { get; set; }
  27. public string? Memo { get; set; }
  28. public string CreatedAt { get; set; } = default!;
  29. }
  30. public async Task<IActionResult> OnGetAsync(int id, CancellationToken ct)
  31. {
  32. var txResult = await mediator.Send(new GetWalletTransaction.Query(id), ct);
  33. if (txResult.IsFailure)
  34. {
  35. TempData["ErrorMessages"] = txResult.Error.Description;
  36. return RedirectToPage("List");
  37. }
  38. var result = txResult.Value;
  39. Detail = new TransactionDetail
  40. {
  41. ID = result.ID,
  42. WalletKey = result.WalletKey,
  43. WalletID = result.WalletID,
  44. MemberID = result.MemberID,
  45. MemberEmail = result.MemberEmail,
  46. MemberName = result.MemberName,
  47. WalletBalance = result.WalletBalance.ToString("N0"),
  48. WalletDonationBalance = result.WalletDonationBalance.ToString("N0"),
  49. TxType = GetTxTypeName(result.TxType),
  50. BalanceType = GetBalanceTypeName(result.BalanceType),
  51. Amount = result.Amount.ToString("N0"),
  52. BalanceAfter = result.BalanceAfter.ToString("N0"),
  53. Reason = result.Reason,
  54. RefID = result.RefID,
  55. UserID = result.UserID,
  56. Memo = result.Memo,
  57. CreatedAt = result.CreatedAt.GetDateAt()
  58. };
  59. return Page();
  60. }
  61. private static string GetTxTypeName(WalletTransactionType type) => type switch
  62. {
  63. WalletTransactionType.Charge => "충전",
  64. WalletTransactionType.DonationIn => "후원 받음",
  65. WalletTransactionType.DonationOut => "후원 보냄",
  66. WalletTransactionType.RewardEarned => "보상 적립",
  67. WalletTransactionType.Spend => "사용",
  68. WalletTransactionType.Refund => "환불",
  69. WalletTransactionType.Lock => "잠금",
  70. WalletTransactionType.Unlock => "잠금 해제",
  71. WalletTransactionType.Adjusted => "조정",
  72. _ => type.ToString()
  73. };
  74. private static string GetBalanceTypeName(WalletBalanceType type) => type switch
  75. {
  76. WalletBalanceType.PgCharged => "PG 충전",
  77. WalletBalanceType.Deposit => "직접 입금",
  78. WalletBalanceType.Donation => "후원",
  79. WalletBalanceType.Reward => "보상",
  80. WalletBalanceType.Airdrop => "에어드랍",
  81. WalletBalanceType.Locked => "잠금",
  82. WalletBalanceType.Adjusted => "조정",
  83. _ => type.ToString()
  84. };
  85. }