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