Files
blazor-cms/Features/Thirdparty/PatientContact/Cqrs/GetPatientContactByIdHandler.cs
T
2026-07-21 13:52:43 +07:00

53 lines
1.9 KiB
C#

using Indotalent.Infrastructure.Database;
using MediatR;
using Microsoft.EntityFrameworkCore;
namespace Indotalent.Features.Thirdparty.PatientContact.Cqrs;
public class GetPatientContactByIdResponse
{
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? Description { get; set; }
public string? PatientId { get; set; }
public DateTimeOffset? CreatedAt { get; set; }
public string? CreatedBy { get; set; }
public DateTimeOffset? UpdatedAt { get; set; }
public string? UpdatedBy { get; set; }
}
public record GetPatientContactByIdQuery(string Id) : IRequest<GetPatientContactByIdResponse?>;
public class GetPatientContactByIdHandler : IRequestHandler<GetPatientContactByIdQuery, GetPatientContactByIdResponse?>
{
private readonly AppDbContext _context;
public GetPatientContactByIdHandler(AppDbContext context) => _context = context;
public async Task<GetPatientContactByIdResponse?> Handle(GetPatientContactByIdQuery request, CancellationToken cancellationToken)
{
return await _context.PatientContact
.AsNoTracking()
.Where(x => x.Id == request.Id)
.Select(x => new GetPatientContactByIdResponse
{
Id = x.Id,
AutoNumber = x.AutoNumber,
Name = x.Name,
Title = x.Title,
PhoneNumber = x.PhoneNumber,
EmailAddress = x.EmailAddress,
Description = x.Description,
PatientId = x.PatientId,
CreatedAt = x.CreatedAt,
CreatedBy = x.CreatedBy,
UpdatedAt = x.UpdatedAt,
UpdatedBy = x.UpdatedBy,
})
.FirstOrDefaultAsync(cancellationToken);
}
}