303 lines
7.7 KiB
C#
303 lines
7.7 KiB
C#
///////////////////////////////////////////////////////////
|
|
// 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
|
|
{
|
|
/// <summary>
|
|
/// User selected delivery method for a single notification subscription
|
|
/// </summary>
|
|
[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
|
|
/// <summary>
|
|
/// Initial created date of this object
|
|
/// </summary>
|
|
public string Created
|
|
{
|
|
get
|
|
{
|
|
return mCreated.ToString();
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// User ID of who initially created this object
|
|
/// </summary>
|
|
public Guid Creator
|
|
{
|
|
get
|
|
{
|
|
return mCreator;
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// Last modified date of this object
|
|
/// </summary>
|
|
public string Modified
|
|
{
|
|
get
|
|
{
|
|
return mModified.ToString();
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// User ID of who last modified this object
|
|
/// </summary>
|
|
public Guid Modifier
|
|
{
|
|
get
|
|
{
|
|
return mModifier;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// ID of parent subscription
|
|
/// </summary>
|
|
public Guid NotifySubscriptionID
|
|
{
|
|
get
|
|
{
|
|
return mNotifySubscriptionID;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// ID of delivery method
|
|
/// </summary>
|
|
public Guid NotifyDeliveryMethodID
|
|
{
|
|
get
|
|
{
|
|
return mNotifyDeliveryMethodID;
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
#region System.object overrides
|
|
|
|
public override string ToString()
|
|
{
|
|
return "NotifySubscriptionDelivery - SubscriptionID: " + mNotifySubscriptionID.ToString() + "DeliveryID: " + mNotifyDeliveryMethodID.ToString();
|
|
}
|
|
|
|
///
|
|
/// <param name="obj"></param>
|
|
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
|
|
/// <summary>
|
|
/// New
|
|
/// </summary>
|
|
/// <param name="NotifySubscriptionID"></param>
|
|
/// <param name="NotifyDeliveryMethodID"></param>
|
|
/// <returns></returns>
|
|
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")));
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// Retrieve item
|
|
/// </summary>
|
|
/// <param name="dr">Data reader</param>
|
|
/// <returns>item from database</returns>
|
|
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
|
|
|
|
/// <summary>
|
|
/// Fetch from db
|
|
/// </summary>
|
|
/// <param name="dr"></param>
|
|
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();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Persist object to database
|
|
/// </summary>
|
|
/// <param name="tr">Parents transaction object</param>
|
|
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 |