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