Handler.cs 869 B

1234567891011121314151617181920212223242526272829
  1. using Application.Abstractions.Data;
  2. using MediatR;
  3. using Microsoft.EntityFrameworkCore;
  4. namespace Application.Features.Popup.Get;
  5. public sealed class Handler(IAppDbContext db) : IRequestHandler<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. Subject = x.Subject,
  16. Content = x.Content,
  17. Link = x.Link,
  18. StartAt = x.StartAt,
  19. EndAt = x.EndAt,
  20. Order = x.Order,
  21. IsActive = x.IsActive,
  22. UpdatedAt = x.UpdatedAt,
  23. CreatedAt = x.CreatedAt
  24. })
  25. .FirstOrDefaultAsync(ct);
  26. }
  27. }