/////////////////////////////////////////////////////////// // NotifySubscriptionDelivery.cs // Implementation of Class NotifySubscriptionDelivery // CSLA type: Editable Child // Created on: 06-Oct-2005 // Object design: John // Coded: John 06-Oct-2005 /////////////////////////////////////////////////////////// using System; using System.Data; using CSLA.Data; using GZTW.Data; using CSLA; using System.Threading; using CSLA.Security; namespace GZTW.AyaNova.BLL { /// /// User selected delivery method for a single notification subscription /// [Serializable] public class NotifySubscriptionDelivery : BusinessBase { #pragma warning disable 1591 #region Attributes //private bool bReadOnly; private Guid mNotifySubscriptionID; private Guid mNotifyDeliveryMethodID; private Guid mCreator; private Guid mModifier; private SmartDate mCreated; private SmartDate mModified; #endregion #region Constructor private NotifySubscriptionDelivery() { //Child object MarkAsChild(); //Set record history to defaults mCreated = new SmartDate(DBUtil.CurrentWorkingDateTime); mModified = new SmartDate(DBUtil.CurrentWorkingDateTime); mCreator=Guid.Empty; mModifier=Guid.Empty; } #endregion #region BusinessProperties //---Common properties /// /// Initial created date of this object /// public string Created { get { return mCreated.ToString(); } } /// /// User ID of who initially created this object /// public Guid Creator { get { return mCreator; } } /// /// Last modified date of this object /// public string Modified { get { return mModified.ToString(); } } /// /// User ID of who last modified this object /// public Guid Modifier { get { return mModifier; } } /// /// ID of parent subscription /// public Guid NotifySubscriptionID { get { return mNotifySubscriptionID; } } /// /// ID of delivery method /// public Guid NotifyDeliveryMethodID { get { return mNotifyDeliveryMethodID; } } #endregion #region System.object overrides public override string ToString() { return "NotifySubscriptionDelivery - SubscriptionID: " + mNotifySubscriptionID.ToString() + "DeliveryID: " + mNotifyDeliveryMethodID.ToString(); } /// /// public override bool Equals(Object obj) { if ( obj == null || GetType ( ) != obj.GetType ( ) ) return false; NotifySubscriptionDelivery c=(NotifySubscriptionDelivery)obj; return (mNotifySubscriptionID==c.mNotifySubscriptionID) && (mNotifyDeliveryMethodID==c.mNotifyDeliveryMethodID) ; } public override int GetHashCode() { return this.ToString().GetHashCode(); } #endregion #region Static methods /// /// New /// /// /// /// internal static NotifySubscriptionDelivery NewItem(Guid NotifySubscriptionID, Guid NotifyDeliveryMethodID) { if(AyaBizUtils.Right("Object.Notification")>(int)SecurityLevelTypes.ReadOnly) { NotifySubscriptionDelivery child=new NotifySubscriptionDelivery(); child.mNotifySubscriptionID=NotifySubscriptionID; child.mNotifyDeliveryMethodID=NotifyDeliveryMethodID; return child; } else throw new System.Security.SecurityException( string.Format( LocalizedTextTable.GetLocalizedTextDirect("Error.Security.NotAuthorizedToCreate"), LocalizedTextTable.GetLocalizedTextDirect("O.Notification"))); } /// /// Retrieve item /// /// Data reader /// item from database internal static NotifySubscriptionDelivery GetItem(SafeDataReader dr) { if(AyaBizUtils.Right("Object.Notification")>(int)SecurityLevelTypes.NoAccess || AyaBizUtils.IsGenerator) { NotifySubscriptionDelivery child = new NotifySubscriptionDelivery(); child.Fetch(dr); return child; } else throw new System.Security.SecurityException( string.Format( LocalizedTextTable.GetLocalizedTextDirect("Error.Security.NotAuthorizedToRetrieve"), LocalizedTextTable.GetLocalizedTextDirect("O.Notification"))); } #endregion #region DAL DATA ACCESS /// /// Fetch from db /// /// private void Fetch(SafeDataReader dr) { //Standard items mCreated=DBUtil.ToLocal(dr.GetSmartDate("aCreated")); mCreator=dr.GetGuid("aCreator"); mModified=DBUtil.ToLocal(dr.GetSmartDate("aModified")); mModifier=dr.GetGuid("aModifier"); this.mNotifySubscriptionID=dr.GetGuid("aNotifySubscriptionID"); this.mNotifyDeliveryMethodID=dr.GetGuid("aNotifyDeliveryMethodID"); MarkOld(); } /// /// Persist object to database /// /// Parents transaction object internal void Update(IDbTransaction tr) { //Note that this is a write or delete object //so much of the code related to updating has been removed //deliberately as it's not needed //No need to update if there is nothing changed if(!this.IsDirty) return; #region Delete if(IsDeleted) { if(!IsNew) { DBCommandWrapper cmDelete = DBUtil.GetCommandFromSQL( "DELETE FROM aNotifySubscriptionDelivery " + "WHERE aNotifySubscriptionID=@NotifySubscriptionID " + "AND aNotifyDeliveryMethodID=@NotifyDeliveryMethodID;"); cmDelete.AddInParameter("@NotifySubscriptionID",DbType.Guid,this.mNotifySubscriptionID); cmDelete.AddInParameter("@NotifyDeliveryMethodID",DbType.Guid,this.mNotifyDeliveryMethodID); DBUtil.DB.ExecuteNonQuery(cmDelete, tr); } MarkNew(); return; } #endregion #region Add / Update //get modification time temporarily, if update succeeds then //set to this time System.DateTime dtModified = DBUtil.CurrentWorkingDateTime; DBCommandWrapper cm = null; if(IsNew)//Add or update? cm=DBUtil.GetCommandFromSQL( "INSERT INTO aNotifySubscriptionDelivery (aNotifySubscriptionID, " + "aNotifyDeliveryMethodID, aCreated,aModified,aCreator, " + "aModifier) VALUES (@NotifySubscriptionID, " + "@NotifyDeliveryMethodID,@Created,@Modified,@CurrentUserID,@CurrentUserID)" ); else throw new ApplicationException("NotifySubscriptionDelivery can only be created or deleted, not modified"); //NotifySubscriptionDelivery specific parameters cm.AddInParameter("@NotifySubscriptionID",DbType.Guid,this.mNotifySubscriptionID); cm.AddInParameter("@NotifyDeliveryMethodID",DbType.Guid,this.mNotifyDeliveryMethodID); //standard parameters cm.AddInParameter("@CurrentUserID",DbType.Guid, CurrentUserID); cm.AddInParameter("@Created", DbType.DateTime, DBUtil.ToUTC(DBUtil.CurrentWorkingDateTime)); cm.AddInParameter("@Modified", DbType.DateTime, DBUtil.ToUTC(DBUtil.CurrentWorkingDateTime)); DBUtil.DB.ExecuteNonQuery(cm, tr); MarkOld();//db is now synched with object #endregion } #endregion #pragma warning restore 1591 }//end NotifySubscriptionDelivery }//end namespace GZTW.AyaNova.BLL