NotificationSubscriptionSynchronizer.cs 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. using Abp.Dependency;
  2. using Abp.Domain.Repositories;
  3. using Abp.Domain.Uow;
  4. using Abp.Events.Bus.Entities;
  5. using Abp.Events.Bus.Handlers;
  6. using Abp.Notifications;
  7. using VberZero.BaseSystem.Users;
  8. namespace VberZero.Notifications;
  9. public class NotificationSubscriptionSynchronizer : IEventHandler<EntityDeletedEventData<User>>,
  10. ITransientDependency
  11. {
  12. private readonly IRepository<NotificationSubscriptionInfo, Guid> _notificationSubscriptionRepository;
  13. private readonly IUnitOfWorkManager _unitOfWorkManager;
  14. public NotificationSubscriptionSynchronizer(
  15. IRepository<NotificationSubscriptionInfo, Guid> notificationSubscriptionRepository,
  16. IUnitOfWorkManager unitOfWorkManager
  17. )
  18. {
  19. _notificationSubscriptionRepository = notificationSubscriptionRepository;
  20. _unitOfWorkManager = unitOfWorkManager;
  21. }
  22. public virtual void HandleEvent(EntityDeletedEventData<User> eventData)
  23. {
  24. _unitOfWorkManager.WithUnitOfWork(() =>
  25. {
  26. using (_unitOfWorkManager.Current.SetTenantId(eventData.Entity.TenantId))
  27. {
  28. _notificationSubscriptionRepository.Delete(x => x.UserId == eventData.Entity.Id);
  29. }
  30. });
  31. }
  32. }