using System; using System.ComponentModel.DataAnnotations.Schema; namespace Oqtane.Models { /// /// Notification for a User - usually meant to be sent as an E-Mail. /// public class Notification : IDeletable { /// /// Internal ID /// public int NotificationId { get; set; } /// /// Reference to the on which the Notification was created. /// public int SiteId { get; set; } /// /// Creator ID /// public int? FromUserId { get; set; } /// /// Nice Name of the Creator /// public string FromDisplayName { get; set; } /// /// Creator E-Mail /// public string FromEmail { get; set; } /// /// Recipient ID - nullable, as Recipient could be someone that's not a user. /// public int? ToUserId { get; set; } /// /// Recipient Nice-Name. /// public string ToDisplayName { get; set; } /// /// Recipient Mail /// public string ToEmail { get; set; } /// /// Reference to an optional Parent - in case it's a kind of thread with reply-messages. /// public int? ParentId { get; set; } /// /// Message Subject. /// public string Subject { get; set; } /// /// Body / Contents of this Notification /// public string Body { get; set; } /// /// When the notification was created. /// public DateTime CreatedOn { get; set; } /// /// If it has been delivered. See also . /// public bool IsDelivered { get; set; } /// /// When the Notification was sent/delivered. /// public DateTime? DeliveredOn { get; set; } #region IDeletable /// public string DeletedBy { get; set; } /// public DateTime? DeletedOn { get; set; } /// public bool IsDeleted { get; set; } #endregion /// /// When the Notification _should_ be sent. See also /// public DateTime? SendOn { get; set; } // constructors public Notification() {} public Notification(int siteId, User to, string subject, string body) { ConstructNotification(siteId, null, "", "", to, "", "", subject, body, null, null); } public Notification(int siteId, User to, string subject, string body, DateTime sendOn) { ConstructNotification(siteId, null, "", "", to, "", "", subject, body, null, sendOn); } public Notification(int siteId, User from, User to, string subject, string body) { ConstructNotification(siteId, from, "", "", to, "", "", subject, body, null, null); } public Notification(int siteId, User from, User to, string subject, string body, int? parentId) { ConstructNotification(siteId, from, "", "", to, "", "", subject, body, parentId, null); } public Notification(int siteId, string toDisplayName, string toEmail, string subject, string body) { ConstructNotification(siteId, null, "", "", null, toDisplayName, toEmail, subject, body, null, null); } public Notification(int siteId, string toDisplayName, string toEmail, string subject, string body, DateTime sendOn) { ConstructNotification(siteId, null, "", "", null, toDisplayName, toEmail, subject, body, null, sendOn); } public Notification(int siteId, string fromDisplayName, string fromEmail, string toDisplayName, string toEmail, string subject, string body) { ConstructNotification(siteId, null, fromDisplayName, fromEmail, null, toDisplayName, toEmail, subject, body, null, null); } private void ConstructNotification(int siteId, User from, string fromDisplayName, string fromEmail, User to, string toDisplayName, string toEmail, string subject, string body, int? parentId, DateTime? sendOn) { SiteId = siteId; if (from != null) { FromUserId = from.UserId; FromDisplayName = from.DisplayName; FromEmail = from.Email; } else { FromUserId = null; FromDisplayName = fromDisplayName; FromEmail = fromEmail; } if (to != null) { ToUserId = to.UserId; ToDisplayName = to.DisplayName; ToEmail = to.Email; } else { ToUserId = null; ToDisplayName = toDisplayName; ToEmail = toEmail; } Subject = subject; Body = body; ParentId = parentId; CreatedOn = DateTime.UtcNow; if (sendOn != null) { SendOn = sendOn; } else { SendOn = CreatedOn; } IsDelivered = false; DeliveredOn = null; } } }