Handler.cs 943 B

123456789101112131415161718192021222324252627282930
  1. using Application.Abstractions.Messaging;
  2. using Application.Abstractions.Data;
  3. using Microsoft.EntityFrameworkCore;
  4. namespace Application.Features.Admin.Popup.Get;
  5. public sealed class Handler(IAppDbContext db) : IQueryHandler<Query, Response?>
  6. {
  7. public async Task<Response?> Handle(Query request, CancellationToken ct)
  8. {
  9. return await db.Popup
  10. .AsNoTracking()
  11. .Where(x => x.ID == request.ID)
  12. .Select(x => new Response
  13. {
  14. ID = x.ID,
  15. PositionID = x.PositionID,
  16. Subject = x.Subject,
  17. Content = x.Content,
  18. Link = x.Link,
  19. StartAt = x.StartAt,
  20. EndAt = x.EndAt,
  21. Order = x.Order,
  22. IsActive = x.IsActive,
  23. UpdatedAt = x.UpdatedAt,
  24. CreatedAt = x.CreatedAt
  25. })
  26. .FirstOrDefaultAsync(ct);
  27. }
  28. }