27 lines
964 B
C#
27 lines
964 B
C#
using Indotalent.Infrastructure.Database;
|
|
using MediatR;
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
namespace Indotalent.Features.Thirdparty.PatientGroup.Cqrs;
|
|
|
|
public record DeletePatientGroupByIdRequest(string Id);
|
|
|
|
public record DeletePatientGroupByIdCommand(DeletePatientGroupByIdRequest Data) : IRequest<bool>;
|
|
|
|
public class DeletePatientGroupByIdHandler : IRequestHandler<DeletePatientGroupByIdCommand, bool>
|
|
{
|
|
private readonly AppDbContext _context;
|
|
|
|
public DeletePatientGroupByIdHandler(AppDbContext context) => _context = context;
|
|
|
|
public async Task<bool> Handle(DeletePatientGroupByIdCommand request, CancellationToken cancellationToken)
|
|
{
|
|
var entity = await _context.PatientGroup
|
|
.FirstOrDefaultAsync(x => x.Id == request.Data.Id, cancellationToken);
|
|
|
|
if (entity == null) return false;
|
|
|
|
_context.PatientGroup.Remove(entity);
|
|
return await _context.SaveChangesAsync(cancellationToken) > 0;
|
|
}
|
|
} |