Login.cshtml.cs 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. using SharedKernel.Helpers;
  2. using MediatR;
  3. using Microsoft.AspNetCore.Mvc;
  4. using Microsoft.AspNetCore.Mvc.RazorPages;
  5. using System.ComponentModel;
  6. using System.ComponentModel.DataAnnotations;
  7. using SearchLoginLogs = Application.Features.Member.LoginLog.Search;
  8. namespace Admin.Pages.Member.Log;
  9. public class LoginModel(IMediator mediator) : PageModel
  10. {
  11. [BindProperty(SupportsGet = true)]
  12. public QueryParams Query { get; set; } = new();
  13. public sealed class QueryParams
  14. {
  15. [Range(1, int.MaxValue)]
  16. [DisplayName("페이지 번호")]
  17. public int PageNum { get; set; } = 1;
  18. [Range(1, 100)]
  19. [DisplayName("페이지 목록 수")]
  20. public ushort PerPage { get; set; } = 10;
  21. [DisplayName("계정")]
  22. public string? Account { get; set; }
  23. [DisplayName("결과")]
  24. public bool? Success { get; set; }
  25. }
  26. public int Total { get; set; } = 0;
  27. public List<(
  28. int Num,
  29. int ID,
  30. int? MemberID,
  31. string? MemberName,
  32. string Account,
  33. bool Success,
  34. string? Reason,
  35. string? IpAddress,
  36. string? UserAgent,
  37. string CreatedAt
  38. )> List { get; set; } = [];
  39. public Pagination? Pagination { get; set; }
  40. public async Task OnGetAsync(CancellationToken ct)
  41. {
  42. if (!ModelState.IsValid)
  43. {
  44. return;
  45. }
  46. var result = await mediator.Send(new SearchLoginLogs.Query(
  47. Query.PageNum,
  48. Query.PerPage,
  49. Account: Query.Account,
  50. Success: Query.Success
  51. ), ct);
  52. Total = result.Total;
  53. List = [.. result.List.Select(c => (
  54. c.Num,
  55. c.ID,
  56. c.MemberID,
  57. c.MemberName,
  58. c.Account,
  59. c.Success,
  60. c.Reason,
  61. c.IpAddress,
  62. c.UserAgent,
  63. c.CreatedAt
  64. ))];
  65. Pagination = new Pagination(result.Total, Query.PageNum, Query.PerPage);
  66. }
  67. }