View.cshtml.cs 3.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. using SharedKernel.Extensions;
  2. using Domain.Entities.Wallets.ValueObject;
  3. using MediatR;
  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. try
  33. {
  34. var result = await mediator.Send(new GetWalletTransaction.Query(id), ct);
  35. Detail = new TransactionDetail
  36. {
  37. ID = result.ID,
  38. WalletKey = result.WalletKey,
  39. WalletID = result.WalletID,
  40. MemberID = result.MemberID,
  41. MemberEmail = result.MemberEmail,
  42. MemberName = result.MemberName,
  43. WalletBalance = result.WalletBalance.ToString("N0"),
  44. WalletDonationBalance = result.WalletDonationBalance.ToString("N0"),
  45. TxType = GetTxTypeName(result.TxType),
  46. BalanceType = GetBalanceTypeName(result.BalanceType),
  47. Amount = result.Amount.ToString("N0"),
  48. BalanceAfter = result.BalanceAfter.ToString("N0"),
  49. Reason = result.Reason,
  50. RefID = result.RefID,
  51. UserID = result.UserID,
  52. Memo = result.Memo,
  53. CreatedAt = result.CreatedAt.GetDateAt()
  54. };
  55. }
  56. catch (Exception e)
  57. {
  58. TempData["ErrorMessages"] = e.Message;
  59. return RedirectToPage("List");
  60. }
  61. return Page();
  62. }
  63. private static string GetTxTypeName(WalletTransactionType type) => type switch
  64. {
  65. WalletTransactionType.Charge => "충전",
  66. WalletTransactionType.DonationIn => "후원 받음",
  67. WalletTransactionType.DonationOut => "후원 보냄",
  68. WalletTransactionType.RewardEarned => "보상 적립",
  69. WalletTransactionType.Spend => "사용",
  70. WalletTransactionType.Refund => "환불",
  71. WalletTransactionType.Lock => "잠금",
  72. WalletTransactionType.Unlock => "잠금 해제",
  73. WalletTransactionType.Adjusted => "조정",
  74. _ => type.ToString()
  75. };
  76. private static string GetBalanceTypeName(WalletBalanceType type) => type switch
  77. {
  78. WalletBalanceType.PgCharged => "PG 충전",
  79. WalletBalanceType.Deposit => "직접 입금",
  80. WalletBalanceType.Donation => "후원",
  81. WalletBalanceType.Reward => "보상",
  82. WalletBalanceType.Airdrop => "에어드랍",
  83. WalletBalanceType.Locked => "잠금",
  84. WalletBalanceType.Adjusted => "조정",
  85. _ => type.ToString()
  86. };
  87. }