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; public class DeletePatientContactByIdHandler : IRequestHandler { private readonly AppDbContext _context; public DeletePatientContactByIdHandler(AppDbContext context) => _context = context; public async Task 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; } }