Files
2026-07-21 13:52:43 +07:00

27 lines
984 B
C#

using Indotalent.Infrastructure.Database;
using MediatR;
using Microsoft.EntityFrameworkCore;
namespace Indotalent.Features.Thirdparty.PatientContact.Cqrs;
public record DeletePatientContactByIdRequest(string Id);
public record DeletePatientContactByIdCommand(DeletePatientContactByIdRequest Data) : IRequest<bool>;
public class DeletePatientContactByIdHandler : IRequestHandler<DeletePatientContactByIdCommand, bool>
{
private readonly AppDbContext _context;
public DeletePatientContactByIdHandler(AppDbContext context) => _context = context;
public async Task<bool> Handle(DeletePatientContactByIdCommand request, CancellationToken cancellationToken)
{
var entity = await _context.PatientContact
.FirstOrDefaultAsync(x => x.Id == request.Data.Id, cancellationToken);
if (entity == null) return false;
_context.PatientContact.Remove(entity);
return await _context.SaveChangesAsync(cancellationToken) > 0;
}
}