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