35 lines
982 B
C#
35 lines
982 B
C#
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<DeleteAddressCommand>
|
|
{
|
|
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();
|
|
}
|
|
}
|