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

Saving CreatorUserId When a Notification is Created #11975


User avatar
0
maberry created

Mass notifications and "regular" notifications are stored in the same DB table. The table has a CreatorUserId field. If I create a mass notification the CreatorUserId is populated; however, the field is null if I create a "regular" in app notification. Am I doing something wrong, or is this the expected behavior? If it is the expected behavior, how can I get the CreatorUserId saved when creating all notification types?

    public async Task InvoiceNotificationAsync(Vendor vendor, string hostName, long userId, string userName)
    {
        Logger.Warn($"InvoiceRequestNotificationAsync called");

        var vendorTenantId = 1073;

        var notificationData = new LocalizableMessageNotificationData(
            new LocalizableString(
                "message",
                ERAConsts.LocalizationSourceName
            )
        );

        notificationData["hostName"] = hostName;
        notificationData["recordId"] = vendor.Id;
        notificationData["recordType"] = "vendor";
        notificationData["htmlCheck"] = "Yes";
        notificationData["TenantName"] = vendor.TenantName;
        notificationData["userId"] = userId;
        notificationData["userName"] = userName;

        notificationData["OrderNumber"] = vendor.OrderNumber;
        notificationData["InvoiceRequestDate"] = vendor.InvoiceRequestDate;

        await CurrentUnitOfWork.SaveChangesAsync();

        await _notificationPublisher.PublishAsync(AppNotificationNames.InvoiceRequested, notificationData,
                severity: NotificationSeverity.Warn, 
            tenantIds: new int?[] { vendorTenantId });                
    }

END GOAL

Scenario: User1 creates an order, which triggers a notification to inform User2 a task needs to be completed. User1 then realizes the order needs to be modified so he/she cancels the order. The task is removed from User2's view; however, the notification remains. I've been trying to figure out how to delete the notification when User1 cancels the order. I found this method:

    public async Task<GetPublishedNotificationsOutput> GetNotificationsPublishedByUser(
        GetPublishedNotificationsInput input)
    {
        return new GetPublishedNotificationsOutput(
            await _notificationStore.GetNotificationsPublishedByUserAsync(AbpSession.ToUserIdentifier(),
                AppNotificationNames.MassNotification, input.StartDate, input.EndDate)
        );
    }

I created a copy and changed AppNotificationNames.MassNotification to AppNotificationNames.InvoiceRequested, but then I realized the CreatorUserId is not saved.


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

    Hi,

    Could you share where do you call InvoiceNotificationAsync method ?

  • User Avatar
    0
    maberry created

    InvoiceNotificationAsync method is located in the AppNotifer file.

    The method is being called from the HostAccountAppService file at the end of the update method.

  • User Avatar
    0
    ismcagdas created
    Support Team

    @oguzhanagir could you check this case and offer a solution to @maberry ?

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi @maberry

    Do you login as a host user and then execute HostAccountAppService's method ? If so, could you share related method in HostAccountAppService and also your notification definition in AppNotificationProvider ?