initial commit
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
using Indotalent.Infrastructure.Database;
|
||||
using MediatR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Indotalent.Features.Thirdparty.PatientContact.Cqrs;
|
||||
|
||||
public class LookupPatientContactResponse
|
||||
{
|
||||
public List<LookupItem> Patients { get; set; } = new();
|
||||
}
|
||||
|
||||
public class LookupItem
|
||||
{
|
||||
public string? Id { get; set; }
|
||||
public string? Name { get; set; }
|
||||
}
|
||||
|
||||
public record LookupPatientContactQuery() : IRequest<LookupPatientContactResponse>;
|
||||
|
||||
public class LookupPatientContactHandler : IRequestHandler<LookupPatientContactQuery, LookupPatientContactResponse>
|
||||
{
|
||||
private readonly AppDbContext _context;
|
||||
|
||||
public LookupPatientContactHandler(AppDbContext context) => _context = context;
|
||||
|
||||
public async Task<LookupPatientContactResponse> Handle(LookupPatientContactQuery request, CancellationToken cancellationToken)
|
||||
{
|
||||
var result = new LookupPatientContactResponse();
|
||||
|
||||
result.Patients = await _context.Patient
|
||||
.AsNoTracking()
|
||||
.OrderBy(x => x.Name)
|
||||
.Select(x => new LookupItem { Id = x.Id, Name = x.Name })
|
||||
.ToListAsync(cancellationToken);
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user