using Microsoft.EntityFrameworkCore; using NetinaShop.Domain.Entities.Brands; namespace NetinaShop.Repository.Handlers.Brands; public class DeleteBrandCommandHandler : IRequestHandler { private readonly IRepositoryWrapper _repositoryWrapper; public DeleteBrandCommandHandler(IRepositoryWrapper repositoryWrapper) { _repositoryWrapper = repositoryWrapper; } public async Task Handle(DeleteBrandCommand request, CancellationToken cancellationToken) { var ent = await _repositoryWrapper.SetRepository().TableNoTracking .FirstOrDefaultAsync(b => b.Id == request.Id, cancellationToken); if (ent == null) throw new AppException("Brand not found"); _repositoryWrapper.SetRepository().Delete(ent); await _repositoryWrapper.SaveChangesAsync(cancellationToken); return true; } }