using MediatR; using cuqmbr.TravelGuide.Application.Common.Persistence; using cuqmbr.TravelGuide.Application.Common.Exceptions; namespace cuqmbr.TravelGuide.Application.Addresses.Commands.DeleteAddress; public class DeleteAddressCommandHandler : IRequestHandler { private readonly UnitOfWork _unitOfWork; public DeleteAddressCommandHandler(UnitOfWork unitOfWork) { _unitOfWork = unitOfWork; } public async Task Handle( DeleteAddressCommand request, CancellationToken cancellationToken) { var entity = await _unitOfWork.AddressRepository.GetOneAsync( e => e.Guid == request.Guid, cancellationToken); if (entity == null) { throw new NotFoundException(); } await _unitOfWork.AddressRepository.DeleteOneAsync( entity, cancellationToken); await _unitOfWork.SaveAsync(cancellationToken); _unitOfWork.Dispose(); } }