Index.cshtml.cs 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. namespace Admin.Pages.Donation.Rank;
  8. public class IndexModel(IMediator mediator) : PageModel
  9. {
  10. [BindProperty(SupportsGet = true)]
  11. public QueryParams Query { get; set; } = new();
  12. public sealed class QueryParams
  13. {
  14. [Range(1, int.MaxValue)]
  15. [DisplayName("페이지 번호")]
  16. public int PageNum { get; set; } = 1;
  17. [Range(1, 100)]
  18. [DisplayName("페이지 목록 수")]
  19. public ushort PerPage { get; set; } = 10;
  20. [DisplayName("검색 조건")]
  21. [Range(1, 7, ErrorMessage = "{0}이(가) 올바르지 않습니다.")]
  22. public int? Search { get; set; }
  23. [DisplayName("검색어")]
  24. [MaxLength(100, ErrorMessage = "{0}은(는) {1}자 이하로 입력하세요.")]
  25. public string? Keyword { get; set; }
  26. [DisplayName("시작일")]
  27. public string? StartAt { get; set; }
  28. [DisplayName("종료일")]
  29. public string? EndAt { get; set; }
  30. [DisplayName("탭")]
  31. [Range(0, 6)]
  32. public int Tab { get; set; } = 0;
  33. [DisplayName("정렬")]
  34. [Range(1, 4)]
  35. public int Sort { get; set; } = 1;
  36. }
  37. public int Total { get; set; } = 0;
  38. public List<SearchDonationRanks.Response.Row> 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 SearchDonationRanks.Query(
  47. Query.PageNum,
  48. Query.PerPage,
  49. Query.Search,
  50. Query.Keyword,
  51. Query.StartAt,
  52. Query.EndAt,
  53. Query.Tab,
  54. Query.Sort
  55. ), ct);
  56. Total = result.Total;
  57. List = [.. result.List];
  58. Pagination = new Pagination(result.Total, Query.PageNum, Query.PerPage, Request.QueryString.ToString());
  59. }
  60. }