Base solution for your next web application
Starts in:
01 DAYS
01 HRS
01 MIN
01 SEC
Open Closed

Subscribing Notifications #5247


User avatar
0
ajayak created

I did manual subscription as follow:

private async Task SubscribeCustomerToNotifications(int customerTenantId, LP lpUser, DateTime agreementEndDate)
        {
            var customerTenantUserIds = await UserManager.Users.IgnoreQueryFilters()
                .Where(c => c.TenantId == customerTenantId && !c.IsDeleted)
                .Select(c => c.Id)
                .ToListAsync();
            foreach (var userId in customerTenantUserIds)
            {
                await _notificationSubscriptionManager.SubscribeAsync(
                    new UserIdentifier(customerTenantId, userId), AppNotificationNames.InvoiceGenerated);
            }
        }

and added notification in AppNotificationsProvider as:

context.Manager.Add(
                new NotificationDefinition(
                    AppNotificationNames.InvoiceGenerated,
                    displayName: L("InvoiceGenerated"),
                    permissionDependency: new SimplePermissionDependency(AppPermissions.Pages_PP_SC)
                )
            );

Is it really required for the manual subscription? I see that this notification works fine without explicit subscription:

context.Manager.Add(
                new NotificationDefinition(
                    AppNotificationNames.InvoicePaid,
                    displayName: L("InvoicePaid"),
                    permissionDependency: new SimplePermissionDependency(AppPermissions.Pages_PP_LPA)
                )
            );

2 Answer(s)
  • User Avatar
    0
    ismcagdas created
    Support Team

    @ajayak as far as I remember it depends how you send notification to user. If you directly send notification to user, no need to subscribe but if you send it to a tenant (all users of tenant), then it is send to only subscribed users.

    You can read more here <a class="postlink" href="https://aspnetboilerplate.com/Pages/Documents/Notification-System">https://aspnetboilerplate.com/Pages/Doc ... ion-System</a>.

  • User Avatar
    0
    ajayak created

    <cite>ismcagdas: </cite> @ajayak as far as I remember it depends how you send notification to user. If you directly send notification to user, no need to subscribe but if you send it to a tenant (all users of tenant), then it is send to only subscribed users.

    You can read more here <a class="postlink" href="https://aspnetboilerplate.com/Pages/Documents/Notification-System">https://aspnetboilerplate.com/Pages/Doc ... ion-System</a>.

    Thanks @ismcagdas. I removed the extra code to subscribe and everything still works great!