Files
blazor-swm/Features/Setting/Tax/Cqrs/DeleteTaxByIdHandler.cs
T
2026-07-21 14:35:37 +07:00

27 lines
871 B
C#

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