Notifications
Confinity allows to send notifications to users. This is useful to inform the user about something that the system did that was not immediately requested by the user, e.g. the execution of a publishing task or a export job. The notification title and message can be localized.
Examples
For sending notifications you need to inject the INotificationService and call one of the overloads of SendAsync.
Simple notification
Use this overload when the notification just contains text.
_notificationService.SendAsync(receiver.Id, "Import finished.",
"Your user import finished.");
Notification with link to entities
You can specify entities that can be linked to from your notification.
var users = new List<User>();
_notificationService.SendAsync(receiver.Id, "Import finished.",
"Your data import finished.", users);
Notification with interpolated strings
For interpolated strings you need to implement your own NotificationPayload with public, serializable properties.
var payload = new ImportPayload { ImportedUsersNames = users.Select(p => p.Username).ToList() };
_notificationService.SendAsync(receiver.Id, payload, users);
public sealed class ImportPayload : NotificationPayload
{
public ICollection<string> ImportedUsersNames { get; set; } = [];
public override LocalizedText GetTitle()
{
int count = ImportedUsersNames?.Count ?? 0;
return new LocalizedText("Import of {0} users finished.", count.ToString());
}
public override LocalizedText GetMessage()
{
if (ImportedUsersNames == null || ImportedUsersNames.Any())
return new LocalizedText("Nothing was imported.");
return new LocalizedText("Imported {0} and {1} others.", ImportedUsersNames.First(),
(ImportedUsersNames.Count - 1).ToString());
}
}