Intro.cshtml.cs 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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 SearchIntroChangeLogs = Application.Features.Member.IntroChangeLog.Search;
  8. namespace Admin.Pages.Member.Log;
  9. public class IntroModel(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. }
  22. public int Total { get; set; } = 0;
  23. public List<(
  24. int Num,
  25. int ID,
  26. int MemberID,
  27. string? MemberName,
  28. string? BeforeIntro,
  29. string? AfterIntro,
  30. string? IpAddress,
  31. string CreatedAt
  32. )> List { get; set; } = [];
  33. public Pagination? Pagination { get; set; }
  34. public async Task OnGetAsync(CancellationToken ct)
  35. {
  36. if (!ModelState.IsValid)
  37. {
  38. return;
  39. }
  40. var result = await mediator.Send(new SearchIntroChangeLogs.Query(
  41. Query.PageNum,
  42. Query.PerPage
  43. ), ct);
  44. Total = result.Total;
  45. List = [.. result.List.Select(c => (
  46. c.Num,
  47. c.ID,
  48. c.MemberID,
  49. c.MemberName,
  50. c.BeforeIntro,
  51. c.AfterIntro,
  52. c.IpAddress,
  53. c.CreatedAt
  54. ))];
  55. Pagination = new Pagination(result.Total, Query.PageNum, Query.PerPage);
  56. }
  57. }