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