Handler.cs 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. using Application.Abstractions.Messaging;
  2. using Application.Abstractions.Data;
  3. using Microsoft.EntityFrameworkCore;
  4. namespace Application.Features.Admin.Forum.BoardGroup.GetAll
  5. {
  6. public sealed class Handler(IAppDbContext db) : IQueryHandler<Query, Response>
  7. {
  8. public async Task<Response> Handle(Query request, CancellationToken ct)
  9. {
  10. var items = await db.BoardGroup
  11. .AsNoTracking()
  12. .OrderBy(c => c.Order)
  13. .ThenByDescending(c => c.ID)
  14. .Select(c => new
  15. {
  16. c.ID,
  17. c.Code,
  18. c.Name,
  19. c.Order,
  20. c.Boards,
  21. c.Posts,
  22. c.Comments,
  23. c.UpdatedAt,
  24. c.CreatedAt
  25. })
  26. .ToListAsync(ct);
  27. return new Response(
  28. items.Count,
  29. [..items.Select((c, i) => new Response.Row(
  30. i + 1,
  31. c.ID,
  32. i,
  33. c.Code,
  34. c.Name,
  35. c.Order,
  36. c.Boards,
  37. c.Posts,
  38. c.Comments,
  39. c.UpdatedAt,
  40. c.CreatedAt
  41. ))]);
  42. }
  43. }
  44. }