2024-08-09 21:55:16 +03:30
|
|
|
|
namespace Netina.Repository.Handlers.Addresses;
|
2024-02-12 22:01:15 +03:30
|
|
|
|
|
2024-08-09 21:55:16 +03:30
|
|
|
|
public class DeleteAddressCommandHandler(IRepositoryWrapper repositoryWrapper)
|
|
|
|
|
|
: IRequestHandler<DeleteAddressCommand, bool>
|
2024-02-12 22:01:15 +03:30
|
|
|
|
{
|
|
|
|
|
|
public async Task<bool> Handle(DeleteAddressCommand request, CancellationToken cancellationToken)
|
|
|
|
|
|
{
|
2024-08-09 21:55:16 +03:30
|
|
|
|
var ent = await repositoryWrapper.SetRepository<UserAddress>()
|
2024-02-12 22:01:15 +03:30
|
|
|
|
.TableNoTracking
|
|
|
|
|
|
.FirstOrDefaultAsync(u => u.Id == request.Id, cancellationToken);
|
|
|
|
|
|
if (ent == null)
|
|
|
|
|
|
throw new AppException("Address not found", ApiResultStatusCode.NotFound);
|
2024-08-09 21:55:16 +03:30
|
|
|
|
repositoryWrapper.SetRepository<UserAddress>()
|
2024-02-12 22:01:15 +03:30
|
|
|
|
.Delete(ent);
|
2024-08-09 21:55:16 +03:30
|
|
|
|
await repositoryWrapper.SaveChangesAsync(cancellationToken);
|
2024-02-12 22:01:15 +03:30
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|