Documentation

Add an admin notification

There are two types of admin notifications; persistent and transient. A transient notification will show in the bottom right of the admin screen and show a message, similar to Gmail / Chrome desktop notifications. A persistent notification will be logged in the database and will show in the top right of admin.

To add a new notification you first need to add an event to your code. There are some helper generic classes to help you do this, for example look at IOnAdded<T>. For the hypothetical, let's say you want a new notification for when an order is placed. Firstly, for raising of the event you will need to create an Args class and an Event Type you want. E.G:

public interface IOnOrderPlaced : IEvent   {   }

public class OrderPlacedArgs {  public Order Order { get; set; }  }

Next where you want to raise the event, you would need to add:

EventContext.Instance.Publish(new OrderPlacedArgs { Order = placedOrder });

Now we have the event in place, you can listen to events and use them in notifications. To do this, simply implement your IOnOrderPlaced class like so:

public class OrderPlacedNotification : IOnOrderPlaced

{        

private readonly INotificationPublisher _notificationPublisher;        

public OrderPlacedNotification(INotificationPublisher notificationPublisher)
{

_notificationPublisher = notificationPublisher;        

}

public void Execute(OrderPlacedArgs args)

{

if (args.Order != null && args.Order.BillingAddress != null)

{

var message = string.Format("A new order has been placed by {1}.", args.Order.Id, args.Order.BillingAddress.Name);

_notificationPublisher.PublishNotification(message, PublishType.Both, NotificationType.AdminOnly);

}

}

}

You will note that there is a PublishType enum which allows you to specify if the notification is transient or persistent.