| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- using Application.Abstractions.Data;
- using SharedKernel.Extensions;
- using MediatR;
- using Microsoft.EntityFrameworkCore;
- namespace Application.Features.Faq.Category.Get
- {
- public sealed class Handler(IAppDbContext db) : IRequestHandler<Query, Response>
- {
- public async Task<Response> Handle(Query request, CancellationToken ct)
- {
- var items = await db.FaqCategory
- .AsNoTracking()
- .Include(c => c.FaqItems)
- .OrderBy(c => c.Order)
- .ThenByDescending(c => c.ID)
- .Select(c => new
- {
- c.ID,
- c.Code,
- c.Subject,
- c.Order,
- c.IsActive,
- FaqItemCount = c.FaqItems.Count,
- c.UpdatedAt,
- c.CreatedAt
- })
- .ToListAsync(ct);
- int total = items.Count;
- var rows = items.Select((c, index) => new Response.Row(
- Num: total - index,
- ID: c.ID,
- Index: index,
- Code: c.Code,
- Subject: c.Subject,
- Order: c.Order,
- IsActive: c.IsActive,
- (ushort)c.FaqItemCount,
- c.UpdatedAt.GetDateAt() ?? "-",
- c.CreatedAt.GetDateAt()
- )).ToList();
- return new Response(total, rows);
- }
- }
- }
|