Base solution for your next web application

Activities of "razkhan78"

==============================AppNotificationProvider.cs==============================

/* Document create */
context.Manager.Add(
	new NotificationDefinition(
        AppNotificationNames.NewDocumentCreated,
        displayName: L("NewDocumentCreatedNotificationDefinition"),
        permissionDependency: new SimplePermissionDependency(AppPermissions.Pages_Documents_Create)
        )
);

/* Document type update */
context.Manager.Add(
	new NotificationDefinition(
        AppNotificationNames.DocumentTypeChanged,
        displayName: L("DocumentTypeChangedNotificationDefinition"),
        permissionDependency: new SimplePermissionDependency(AppPermissions.Pages_Documents_Edit)
        )
);


==============================NotificationAppService.cs==============================

	public async Task<GetNotificationSettingsOutput> GetNotificationSettings()
        {
            var output = new GetNotificationSettingsOutput();

            output.ReceiveNotifications = await SettingManager.GetSettingValueAsync<bool>(NotificationSettingNames.ReceiveNotifications);

            /*Get general notifications, not entity related notifications*/
            //var notificationDefinitions = (await _notificationDefinitionManager.GetAllAvailableAsync(AbpSession.ToUserIdentifier())).Where(nd => nd.EntityType == null);

            /*Get all notifications (general+entity related)*/
            var notificationDefinitions = (await _notificationDefinitionManager.GetAllAvailableAsync(AbpSession.ToUserIdentifier()));

            output.Notifications = ObjectMapper.Map<List<NotificationSubscriptionWithDisplayNameDto>>(notificationDefinitions);

            var subscribedNotifications = (await _notificationSubscriptionManager
                .GetSubscribedNotificationsAsync(AbpSession.ToUserIdentifier()))
                .Select(ns => ns.NotificationName)
                .ToList();

            output.Notifications.ForEach(n => n.IsSubscribed = subscribedNotifications.Contains(n.Name));

            return output;
        }

        public async Task UpdateNotificationSettings(UpdateNotificationSettingsInput input)
        {
            await SettingManager.ChangeSettingForUserAsync(AbpSession.ToUserIdentifier(), NotificationSettingNames.ReceiveNotifications, input.ReceiveNotifications.ToString());

            foreach (var notification in input.Notifications)
            {
                if (notification.IsSubscribed)
                {
                    await _notificationSubscriptionManager.SubscribeAsync(AbpSession.ToUserIdentifier(), notification.Name);                    
                }
                else
                {
                    await _notificationSubscriptionManager.UnsubscribeAsync(AbpSession.ToUserIdentifier(), notification.Name);
                }
            }
        }

==============================AppNotifier.cs==============================

/*We have called this function on Document save method:*/

await _notificationPublisher.PublishAsync(AppNotificationNames.NewDocumentCreated, notificationData, null,
                    NotificationSeverity.Info, null, excludedUserIds: new[] { createdByUser.ToUserIdentifier() });

/*We have called this function on change of Document type:*/

await _notificationPublisher.PublishAsync(AppNotificationNames.DocumentTypeChanged, notificationData, null,
                    NotificationSeverity.Info, null, excludedUserIds: new[] { createdByUser.ToUserIdentifier() });

We have passed required dynamic fields values in notification data object.

In database, subscriptions and tenant notifications are populating fine still it is creating issues in Notifications.

We are implementing Notifications for Create events as well some of update data event.

We have one table called "Document". We have implemented Notifications for following cases with specific tenant:

  1. When user creates new document.
  2. When user changes Document type

In Notification setting, two entries will be displayed with checkboxes:

  1. On New Document creation
  2. On Document type change

Issue:

Case 1(Working): If we subscribe for "On New Document creation" and "On Document type change" everything works fine and both types of notifications will be sent to subscribed users. Case 2(Working): If we subscribe only for "On New Document creation" everything works fine and notification will be sent to subscribed users only for new document creation. Case 3(Not Working): If we subscribe only for "On Document type change" and NOT SUBSCRIBE for "On New Document creation" then notification will not be sent to subscribed users. Case 4(Not Working): If we subscribe only for "On New Document creation" and NOT SUBSCRIBE for "On Document type change" then also notification will be sent for both events. If we remove subscription for "On New Document creation" then only "On Document type change" event notification won't be sent.

For all cases, AbpNotificationSubscription table is populated perfectly as per notification selection from Setting screen. Issue occures only with sending notifications.

We are calling PublishAsync as per following: await _notificationPublisher.PublishAsync("App.NewDocumentCreated", notificationData, null,NotificationSeverity.Info, null, excludedUserIds: new[] { createdByUser.ToUserIdentifier() });

As per our understanding, this method will only send notifications to subscribed users which is not working in our system.

It seems like data update Notification subscription is dependent on data create notification. Please suggest how we can solve these issues.

All fields in AbpTenantNotifications table are same except "CreationTime".

We are facing this issue only in our server. In Local, everything is working fine. We have hosted our application on Azure. Is there any setting that we might need to do for Notifications in Azure?

Hi @ismcagdas, We have added logs and there is only one log for "NewEntityCreatedAsync" method. We have also added logs before and after "PublishAsync" method but only one log is created.

Please let us know how can we track this issue.

We have debugged code found that and NewEntityCreatedAsync is called only one time. Issue is, this error is not occuring always. So we are not able to track this. Still we will add logs for these methods and try once.

Thank you

We have added seperate Notification definitions for each Entity and created generalized Publish notification methods for all including below methods. -"CommonMethodHelper.GetNotificationNameFromEntity" will get Notification name as per given entity. -"CommonMethodHelper.GetNotificationTextLocalizationString" will get Notification text message with provided dynamic parameters -"GetEntityTypeByEntityName" will get Entity Type(Document) from given Entity name(string)

No, we have only on 1 instance.

Thank you for quick response. Now I understand all scenarios. I have one more query regarding Publish Notification.

-It is working fine in local and server too. But in server sometimes it is sending notifications twice. 1st is with IST(local system time from where we are testing system) and 2nd is with UTC time(server time). In database also, AbpTenantNotifications table is having two rows with different CreationTime values. Can you help me in this issue?

Code is working fine and we have not called Publish notification method twice still it is calling two times sometimes.

Please let us know your response.

Thanks.

AbpNotificationSubscriptions table is having "EntityId" and "EntityTypeName" columns. We have implemented Notification when any user add data in our custom table X. We have also set Entity Type in AppNotificationProvider.cs file as "typeof(X)". Our notifications are being displayed on Notification Settings page.

In our case, when user subscribes for notification, EntityId and EntityType saved as NULL in database.
When notification is published, that time also EntityId and EntityType saved as NULL in database.

Following are our questions for Insert operation notification:

  1. For our case, these types of Notification can be called General or Entity based?
  2. For insert operation, EntityTypeName should be saved in "AbpNotificationSubsciptions" table or not?
  3. For insert operation, EntityTypeName and EntityId should be saved in "AbpTenantNotifications" table or not?
Showing 81 to 90 of 92 entries