using Indotalent.Infrastructure.Database; using MediatR; using Microsoft.EntityFrameworkCore; namespace Indotalent.Features.Thirdparty.PatientContact.Cqrs; public class GetPatientContactListResponse { public string? Id { get; set; } public string? AutoNumber { get; set; } public string? Name { get; set; } public string? Title { get; set; } public string? PhoneNumber { get; set; } public string? EmailAddress { get; set; } public string? PatientName { get; set; } } public record GetPatientContactListQuery() : IRequest>; public class GetPatientContactListHandler : IRequestHandler> { private readonly AppDbContext _context; public GetPatientContactListHandler(AppDbContext context) => _context = context; public async Task> Handle(GetPatientContactListQuery request, CancellationToken cancellationToken) { return await _context.PatientContact .AsNoTracking() .Include(x => x.Patient) .OrderBy(x => x.Name) .Select(x => new GetPatientContactListResponse { Id = x.Id, AutoNumber = x.AutoNumber, Name = x.Name, Title = x.Title, PhoneNumber = x.PhoneNumber, EmailAddress = x.EmailAddress, PatientName = x.Patient != null ? x.Patient.Name : string.Empty }) .ToListAsync(cancellationToken); } }