Back to Devexpress

How to: Use Notifications with a Custom Business Class (Implement ISupportNotifications)

expressappframework-113689-event-planning-and-notifications-how-to-use-notifications-with-a-custom-business-class.md

latest3.2 KB
Original Source

How to: Use Notifications with a Custom Business Class (Implement ISupportNotifications)

  • Jun 10, 2024
  • 4 minutes to read

This example demonstrates how to associate Notifications with a custom business class.

Assume you have the following MyTask business class.

csharp
using System;
using System.Collections.Generic;
using System.ComponentModel;
using DevExpress.Persistent.Base;
using DevExpress.Persistent.BaseImpl.EF;

namespace MySolution.Module.BusinessObjects;
[DefaultClassOptions]
 public class MyTask : BaseObject {
    public virtual string Subject { get; set; }
    public virtual DateTime DueDate { get; set; }
}

// Make sure that you use options.UseChangeTrackingProxies() in your DbContext settings.
csharp
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DevExpress.Persistent.Base;
using DevExpress.Persistent.BaseImpl;
using DevExpress.Xpo;

namespace MySolution.Module.BusinessObjects;
[DefaultClassOptions]
public class MyTask : BaseObject {
    public MyTask(Session session) : base(session) { }
    public string Subject {
        get {
            return GetPropertyValue<string>(nameof(Subject));
        }
        set {
            SetPropertyValue(nameof(Subject), value);
        }
    }
    public DateTime DueDate {
        get {
            return GetPropertyValue<DateTime>(nameof(DueDate));
        }
        set {
            SetPropertyValue(nameof(DueDate), value);
        }
    }
}

The goal is to use the functionality of the Notifications module to send a reminder to a user before the DueDate.

  1. Add the Notifications module to your application.

  2. Implement the ISupportNotifications interface in the MyTask class.

  3. Override the OnSaving method to initialize AlarmTime based on the RemindIn interval specified by a user.

  4. Run the application and create a new overdue task in the past (the DueDate should be earlier than the current time). Specify a non-empty value for the RemindIn property that defines the time between the notification alert and the DueDate moment (an empty RemindIn value means that the alert is never displayed).

  5. Save the task. The Notifications window should appear after the time span specified in the NotificationsOptionsBase.NotificationsRefreshInterval property or sooner.

See Also

How to: Use Notifications with the Scheduler Event

How to: Show Notifications to a Specific User