CEL_Payroll/Payroll.BO/Notifications/Notification.cs

441 lines
14 KiB
C#
Raw Normal View History

2024-09-17 14:30:13 +06:00
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Ease.CoreV35.Caching;
using Ease.CoreV35.Model;
namespace Payroll.BO
{
#region Notification
[Serializable]
public class Notification : BasicBaseObject
{
#region Cache Store
private static Cache _cache = new Cache(typeof(Notification));
#endregion
#region Constructor
public Notification()
{
_sSubject = string.Empty;
_sFooter = string.Empty;
_sAttachment = string.Empty;
_nTagOutputID = null;
_nObjectID = null;
_nOptionalObjectID = null;
_sBody = string.Empty;
_oNotificationParticipants = null;
_oNotificationRules = null;
_bIsMailNf = false;
_bIsSMSNf = false;
_bIsWebNf = false;
_eStatus = EnumNotificationStatus.Closed;
_eType = EnumNotificationType.Notification;
_nObjectID = ID.FromInteger(0);
_nOptionalObjectID = ID.FromInteger(0);
}
#endregion
#region Properties
#region Subject : string
private string _sSubject;
public string Subject
{
get { return _sSubject; }
set { _sSubject = value; }
}
#endregion
#region Body : string
private string _sBody;
public string Body
{
get { return _sBody; }
set { _sBody = value; }
}
#endregion
#region TagOutputID : ID
private ID _nTagOutputID;
public ID TagOutputID
{
get { return _nTagOutputID; }
set { _nTagOutputID = value; }
}
#endregion
#region ObjectID : ID
private ID _nObjectID;
public ID ObjectID
{
get { return _nObjectID; }
set { _nObjectID = value; }
}
#endregion
#region OptionalObjectID : ID
private ID _nOptionalObjectID;
public ID OptionalObjectID
{
get { return _nOptionalObjectID; }
set { _nOptionalObjectID = value; }
}
#endregion
#region Attachment : string
private string _sAttachment;
public string Attachment
{
get { return _sAttachment; }
set { _sAttachment = value; }
}
#endregion
#region Footer : string
private string _sFooter;
public string Footer
{
get { return _sFooter; }
set { _sFooter = value; }
}
#endregion
#region Type :EnumNotificationType
private EnumNotificationType _eType;
public EnumNotificationType Type
{
get { return _eType; }
set { _eType = value; }
}
#endregion
#region IsWebNf : bool
private bool _bIsWebNf;
public bool IsWebNf
{
get { return _bIsWebNf; }
set {_bIsWebNf=value; }
}
#endregion
#region IsMailNf : bool
private bool _bIsMailNf;
public bool IsMailNf
{
get { return _bIsMailNf; }
set { _bIsMailNf = value; }
}
#endregion
#region IsSMSNf : bool
private bool _bIsSMSNf;
public bool IsSMSNf
{
get { return _bIsSMSNf; }
set { _bIsSMSNf = value; }
}
#endregion
#region Status : EnumNotificationStatus
private EnumNotificationStatus _eStatus;
public EnumNotificationStatus Status
{
get { return _eStatus; }
set { _eStatus = value; }
}
#endregion
#region NotificationParticipants : ObjectsTemplate<NotificationPerticipant>
private ObjectsTemplate<NotificationParticipant> _oNotificationParticipants;
public ObjectsTemplate<NotificationParticipant> NotificationParticipants
{
get
{
if (this.ID != null && _oNotificationParticipants==null)
{
_oNotificationParticipants = Notification.Service.GetNotificationParticipants(this.ID);
}
return _oNotificationParticipants;
}
set { _oNotificationParticipants = value; }
}
#endregion
#region NotificationRules : ObjectsTemplate<NotificationRule>
private ObjectsTemplate<NotificationRule> _oNotificationRules;
public ObjectsTemplate<NotificationRule> NotificationRules
{
get
{
if (this.ID != null && _oNotificationRules == null)
{
_oNotificationRules = Notification.Service.GetNotificationRules(this.ID);
}
return _oNotificationRules;
}
set { _oNotificationRules = value; }
}
#endregion
#region Service Factory
internal static INotificationService Service
{
get { return Services.Factory.CreateService<INotificationService>(typeof(INotificationService)); }
}
#endregion
#endregion
#region Functions
public static int GetNewID()
{
return Notification.Service.GetNewID();
}
public static Notification Get(ID notificationId)
{
Notification oNotification = null;
#region Cache Header
oNotification = (Notification)_cache["Get", notificationId];
if (oNotification != null)
return oNotification;
#endregion
oNotification = Notification.Service.Get(notificationId);
#region Cache Footer
_cache.Add(oNotification, "Get", notificationId);
#endregion
return oNotification;
}
public ID Save()
{
if (User.CurrentUser!=null)
this.SetAuditTrailProperties();
return Notification.Service.Save(this);
}
public static void SaveReply(NotificationParticipant oParticipant)
{
Notification.Service.SaveReply(oParticipant);
}
public void Delete()
{
Notification.Service.Delete(this.ID);
}
public static int GetNewBatchNumber()
{
int batchNo = 0;
batchNo = Notification.Service.GetNewBatchNumber();
return batchNo;
}
public DateTime GetMinSendDateByID()
{
DateTime minDate = DateTime.MinValue;
minDate = Notification.Service.GetMinSendDateByID(this.ID);
return minDate;
}
public static void ChangeNotificationRuleStatus(NotificationRule notfRule, EnumSendStatus enumSendStatus, EnumNotificationMedium medium)
{
switch (medium)
{
case EnumNotificationMedium.Email:
notfRule.EmailSendStatus = enumSendStatus;
break;
case EnumNotificationMedium.SMS:
notfRule.SMSSendStatus = enumSendStatus;
break;
case EnumNotificationMedium.WEB:
notfRule.WebSendStatus = enumSendStatus;
break;
}
Notification.Service.UpdateNotificationRule(notfRule);
}
public static void ChangeNotificationRuleRemarks(NotificationRule notfRule,string Message, EnumNotificationMedium medium)
{
switch (medium)
{
case EnumNotificationMedium.Email:
notfRule.Remarks = "Email Cannot Be sent Due To:" + Message;
break;
case EnumNotificationMedium.SMS:
notfRule.Remarks = "SMS Cannot Be sent Due To:" + Message ;
break;
case EnumNotificationMedium.WEB:
notfRule.Remarks = "Web Notification Cannot Be sent Due To:" + Message;
break;
}
Notification.Service.UpdateNotificationRule(notfRule);
}
#endregion
#region Collection Functions
public static ObjectsTemplate<Notification> Get()
{
#region Cache Header
ObjectsTemplate<Notification> notifications = _cache["Get"] as ObjectsTemplate<Notification>;
if (notifications != null)
return notifications;
#endregion
notifications = Notification.Service.Get();
#region Cache Footer
_cache.Add(notifications, "Get");
#endregion
return notifications;
}
public static ObjectsTemplate<Notification> Get(EnumNotificationStatus status)
{
#region Cache Header
ObjectsTemplate<Notification> notifications = _cache["Get"] as ObjectsTemplate<Notification>;
if (notifications != null)
return notifications;
#endregion
notifications = Notification.Service.Get(status);
#region Cache Footer
_cache.Add(notifications, "Get");
#endregion
return notifications;
}
public static ObjectsTemplate<Notification> GetByDateRange(DateTime startDate, DateTime endDate)
{
ObjectsTemplate<Notification> oNotifications = null;
#region Cache Header
oNotifications = (ObjectsTemplate<Notification>)_cache["Get", startDate, endDate];
if (oNotifications != null)
return oNotifications;
#endregion
oNotifications = Notification.Service.GetByDateRange(startDate, endDate);
#region Cache Footer
_cache.Add(oNotifications, "Get", startDate, endDate);
#endregion
return oNotifications;
}
public static ObjectsTemplate<NotificationParticipant> GetNotificationParticipants(ID notificationID)
{
ObjectsTemplate<NotificationParticipant> oNotificationParticipants = null;
#region Cache Header
oNotificationParticipants = (ObjectsTemplate<NotificationParticipant>)_cache["Get", notificationID];
if (oNotificationParticipants != null)
return oNotificationParticipants;
#endregion
oNotificationParticipants = Notification.Service.GetNotificationParticipants(notificationID);
#region Cache Footer
_cache.Add(oNotificationParticipants, "Get", notificationID);
#endregion
return oNotificationParticipants;
}
#endregion
//public static List<Notification> GetMeetingMinutesForWeb()
//{
// List<Notification> notifcationList = new List<Notification>();
// #region Cache Header
// ObjectsTemplate<Notification> notifications = _cache["Get"] as ObjectsTemplate<Notification>;
// if (notifications != null)
// return notifications;
// #endregion
// notifications = Notification.Service.Get();
// notifcationList = notifications
// .Where(obj => obj.Type == EnumNotificationType.Meeting_Minutes
// && obj.Status == EnumNotificationStatus.InProcess
// )
// .ToList();
// #region Cache Footer
// _cache.Add(notifications, "Get");
// #endregion
// return notifcationList;
//}
public static List<Notification> GetMeetingMinutesForWeb(int webEmployeeID)
{
List<Notification> notifcationList = new List<Notification>();
#region Cache Header
ObjectsTemplate<Notification> notifications = _cache["Get"] as ObjectsTemplate<Notification>;
if (notifications != null)
return notifications;
#endregion
notifications = Notification.Service.Get();
notifcationList = notifications
.Where(obj => obj.Type == EnumNotificationType.Meeting_Minutes
&& obj.Status == EnumNotificationStatus.InProcess
&& obj.NotificationRules.Any(o => o.PerticipantID.Integer == webEmployeeID))
.ToList();
#region Cache Footer
_cache.Add(notifications, "Get");
#endregion
return notifcationList;
}
public static List<Notification> GetNotificationsForWeb(int webEmployeeID)
{
List<Notification> notifcationList = new List<Notification>();
#region Cache Header
ObjectsTemplate<Notification> notifications = _cache["Get"] as ObjectsTemplate<Notification>;
if (notifications != null)
return notifications;
#endregion
notifications = Notification.Service.Get();
notifcationList = notifications
.Where(obj => obj.Type == EnumNotificationType.Notification
&& obj.Status == EnumNotificationStatus.InProcess
&& obj.NotificationRules.Any(o => o.PerticipantID.Integer == webEmployeeID && o.WebSendStatus==EnumSendStatus.NotSent))
.ToList();
#region Cache Footer
_cache.Add(notifications, "Get");
#endregion
return notifcationList;
}
}
#endregion
#region INotification Service
public interface INotificationService
{
int GetNewID();
Notification Get(ID id);
ObjectsTemplate<Notification> Get();
ObjectsTemplate<Notification> Get(EnumNotificationStatus status);
ID Save(Notification oNotification);
void SaveReply(NotificationParticipant oParticipant);
void UpdateNotificationRule(NotificationRule notfRule);
void Delete(ID id);
ObjectsTemplate<NotificationParticipant> GetNotificationParticipants(ID id);
ObjectsTemplate<NotificationRule> GetNotificationRules(ID id);
int GetNewBatchNumber();
DateTime GetMinSendDateByID(ID iD);
ObjectsTemplate<Notification> GetByDateRange(DateTime startDate, DateTime endDate);
}
#endregion
}