226 lines
5.6 KiB
C#
226 lines
5.6 KiB
C#
///////////////////////////////////////////////////////////
|
|
// NotifySubscriptionDeliveries.cs
|
|
// Implementation of Class NotifySubscriptionDeliveries
|
|
// CSLA type: Editable Grandchild collection
|
|
// Created on: 06-Oct-2005
|
|
// Object design: John
|
|
// Coded: John 06-Oct-2005
|
|
///////////////////////////////////////////////////////////
|
|
|
|
using System;
|
|
using GZTW.Data;
|
|
using System.Data;
|
|
using CSLA.Data;
|
|
using CSLA;
|
|
|
|
namespace GZTW.AyaNova.BLL
|
|
{
|
|
/// <summary>
|
|
/// Collection of delivery methods for a notification subscription
|
|
/// </summary>
|
|
[Serializable]
|
|
public class NotifySubscriptionDeliveries : BusinessCollectionBase
|
|
{
|
|
|
|
#region Constructor
|
|
|
|
//Private constructor prevents direction instantiation
|
|
private NotifySubscriptionDeliveries()
|
|
{
|
|
//Child
|
|
MarkAsChild();
|
|
AllowSort=false;
|
|
AllowFind=true;
|
|
AllowEdit=true;
|
|
AllowNew=true;
|
|
AllowRemove=true;
|
|
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Business properties and methods
|
|
/// <summary>
|
|
/// Retrieve NotifySubscriptionDelivery by index
|
|
/// </summary>
|
|
/// <param name="Item">Index</param>
|
|
public NotifySubscriptionDelivery this[int Item]
|
|
{
|
|
get
|
|
{
|
|
return (NotifySubscriptionDelivery) List[Item];
|
|
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Remove by Guid value of ID
|
|
/// </summary>
|
|
/// <param name="NotifySubscriptionID"></param>
|
|
/// <param name="NotifyDeliveryMethodID"></param>
|
|
public void Remove(Guid NotifySubscriptionID, Guid NotifyDeliveryMethodID)
|
|
{
|
|
foreach (NotifySubscriptionDelivery child in List)
|
|
{
|
|
if(child.NotifyDeliveryMethodID==NotifyDeliveryMethodID && child.NotifySubscriptionID == NotifySubscriptionID)
|
|
List.Remove(child);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Add a new NotifySubscriptionDelivery to the collection
|
|
/// </summary>
|
|
/// <param name="NotifySubscriptionID"></param>
|
|
/// <param name="NotifyDeliveryMethodID"></param>
|
|
/// <returns></returns>
|
|
public NotifySubscriptionDelivery Add(Guid NotifySubscriptionID, Guid NotifyDeliveryMethodID)
|
|
{
|
|
NotifySubscriptionDelivery child=NotifySubscriptionDelivery.NewItem(NotifySubscriptionID, NotifyDeliveryMethodID);
|
|
List.Add(child);
|
|
return child;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Contains
|
|
|
|
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="NotifySubscriptionID"></param>
|
|
/// <param name="NotifyDeliveryMethodID"></param>
|
|
/// <returns></returns>
|
|
public bool Contains(Guid NotifySubscriptionID, Guid NotifyDeliveryMethodID)
|
|
{
|
|
foreach (NotifySubscriptionDelivery child in List)
|
|
{
|
|
if(child.NotifyDeliveryMethodID==NotifyDeliveryMethodID && child.NotifySubscriptionID == NotifySubscriptionID)
|
|
return true;
|
|
}
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="NotifySubscriptionID"></param>
|
|
/// <param name="NotifyDeliveryMethodID"></param>
|
|
/// <returns></returns>
|
|
public bool ContainsDeleted(Guid NotifySubscriptionID, Guid NotifyDeliveryMethodID)
|
|
{
|
|
foreach (NotifySubscriptionDelivery child in deletedList)
|
|
{
|
|
if(child.NotifyDeliveryMethodID==NotifyDeliveryMethodID && child.NotifySubscriptionID == NotifySubscriptionID) return true;
|
|
}
|
|
return false;
|
|
|
|
}
|
|
#endregion
|
|
|
|
#region Static methods
|
|
/// <summary>
|
|
/// NewItems
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
internal static NotifySubscriptionDeliveries NewItems()
|
|
{
|
|
return new NotifySubscriptionDeliveries();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Get items - Grandchild style
|
|
/// </summary>
|
|
/// <param name="obj"></param>
|
|
/// <returns></returns>
|
|
internal static NotifySubscriptionDeliveries GetItems(NotifySubscription obj)
|
|
{
|
|
NotifySubscriptionDeliveries col = new NotifySubscriptionDeliveries();
|
|
col.Fetch(obj);
|
|
return col;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region DAL DATA ACCESS
|
|
|
|
/// <summary>
|
|
/// Fetch children - grandchild style
|
|
/// </summary>
|
|
/// <param name="obj"></param>
|
|
private void Fetch(NotifySubscription obj)
|
|
{
|
|
//Load data Grandchild style
|
|
SafeDataReader dr = null;
|
|
try
|
|
{
|
|
dr=DBUtil.GetReaderFromSQLString("SELECT * " +
|
|
"FROM aNotifySubscriptionDelivery " +
|
|
"WHERE aNotifySubscriptionID=@ID",obj.ID);
|
|
while(dr.Read())
|
|
{
|
|
List.Add(NotifySubscriptionDelivery.GetItem(dr));
|
|
}
|
|
}
|
|
finally
|
|
{
|
|
if(dr!=null) dr.Close();
|
|
}
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// Update children
|
|
/// </summary>
|
|
/// <param name="tr"></param>
|
|
internal void Update(IDbTransaction tr)
|
|
{
|
|
//update (thus deleting) any deleted child objects
|
|
foreach (NotifySubscriptionDelivery child in deletedList)
|
|
{
|
|
child.Update(tr);
|
|
}
|
|
|
|
//Now that they are deleted remove them from memory
|
|
deletedList.Clear();
|
|
|
|
foreach (NotifySubscriptionDelivery child in List)
|
|
{
|
|
child.Update(tr);
|
|
|
|
}
|
|
}
|
|
|
|
#region Shared delete method
|
|
/// <summary>
|
|
/// Given a NotifySubscription item ID deletes all delivery items for that ID
|
|
///
|
|
/// Called by Subscription delete
|
|
/// </summary>
|
|
/// <param name="NotifySubscriptionID">ID of parent NotifySubscription object</param>
|
|
/// <param name="transaction">Database transaction from ascendant item</param>
|
|
internal static void DeleteItems(Guid NotifySubscriptionID,IDbTransaction transaction)
|
|
{
|
|
|
|
DBCommandWrapper cmDelete = DBUtil.GetCommandFromSQL(
|
|
"DELETE FROM aNotifySubscriptionDelivery " +
|
|
"WHERE aNotifySubscriptionID=@ID;");
|
|
cmDelete.AddInParameter("@ID",DbType.Guid,NotifySubscriptionID);
|
|
DBUtil.DB.ExecuteNonQuery(cmDelete, transaction);
|
|
|
|
|
|
}
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
}//end NotifySubscriptionDeliveries
|
|
|
|
}//end namespace GZTW.AyaNova.BLL |