public async Task SendRoleAssignedNotification(int?currentTenant, User currentUser, User userAssigned)
        {
            var assignedUserIdentifier = new UserIdentifier(currentTenant, userAssigned.Id);
            var dataToSend             = new LocalizableMessageNotificationData(new LocalizableString("RoleAssignedNotification", AbpModuleZeroConsts.LocalizationSourceName))
            {
                ["userName"]         = currentUser.FullName,
                ["usernameAssigned"] = userAssigned.FullName,
                ["userId"]           = userAssigned.Id
            };
            await
            _notificationPublisher.PublishAsync(NotificationNames.RoleAssigned, dataToSend);

            var isRegistered = await
                               _notificationSubscriptionManager.IsSubscribedAsync(assignedUserIdentifier
                                                                                  , NotificationNames.RoleAssignedToUser);

            if (!isRegistered)
            {
                await _notificationSubscriptionManager.SubscribeAsync(assignedUserIdentifier, NotificationNames.RoleAssignedToUser);
            }
            var dataToSendUser = new LocalizableMessageNotificationData(new LocalizableString("RoleAssignedNotificationToUser", AbpModuleZeroConsts.LocalizationSourceName))
            {
                ["userName"]         = currentUser.FullName,
                ["usernameAssigned"] = userAssigned.FullName,
                ["userId"]           = userAssigned.Id
            };
            await _notificationPublisher.PublishAsync(NotificationNames.RoleAssignedToUser, dataToSendUser, userIds : new[] { assignedUserIdentifier });
        }
예제 #2
0
 /// <summary>
 ///     Checks if a user subscribed for a notification.
 /// </summary>
 /// <param name="notificationSubscriptionManager">Notification subscription manager</param>
 /// <param name="user">User.</param>
 /// <param name="notificationName">Name of the notification.</param>
 /// <param name="entityIdentifier">entity identifier</param>
 public static bool IsSubscribed(this INotificationSubscriptionManager notificationSubscriptionManager,
                                 UserIdentifier user, string notificationName, EntityIdentifier entityIdentifier = null)
 {
     return
         (AsyncHelper.RunSync(
              () => notificationSubscriptionManager.IsSubscribedAsync(user, notificationName, entityIdentifier)));
 }
        public async Task SendRoleDeletedNotification(int tenantId, User user, Role role, long[] userIdsInRole)
        {
            var dataToSend = new LocalizableMessageNotificationData(new LocalizableString("RoleDeletedByUser", AbpModuleZeroConsts.LocalizationSourceName))
            {
                ["roleName"] = role.DisplayName,
                ["user"]     = user.FullName
            };
            await _notificationPublisher.PublishAsync(NotificationNames.RoleDeleted, dataToSend, severity : NotificationSeverity.Warn);

            foreach (var l in userIdsInRole)
            {
                var userIdentifier = new UserIdentifier(tenantId, l);

                if ((!await(_notificationSubscriptionManager.IsSubscribedAsync(userIdentifier, NotificationNames.RoleDeletedForUser))))
                {
                    await _notificationSubscriptionManager.SubscribeAsync(userIdentifier, NotificationNames.RoleDeletedForUser);
                }
            }

            var roleToUserNotificationData = new LocalizableMessageNotificationData(new LocalizableString("RoleDeletedForUser", AbpModuleZeroConsts.LocalizationSourceName));

            await _notificationPublisher.PublishAsync(NotificationNames.RoleDeletedForUser, roleToUserNotificationData, severity : NotificationSeverity.Warn);
        }
예제 #4
0
        public async Task <bool> IsSubscribed(UserIdentifier user, string notificationName)
        {
            var result = await _notificationSubscriptionManager.IsSubscribedAsync(user, notificationName);

            return(result);
        }