///////////////////////////////////////////////////////////
// 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
{
///
/// Collection of delivery methods for a notification subscription
///
[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
///
/// Retrieve NotifySubscriptionDelivery by index
///
/// Index
public NotifySubscriptionDelivery this[int Item]
{
get
{
return (NotifySubscriptionDelivery) List[Item];
}
}
///
/// Remove by Guid value of ID
///
///
///
public void Remove(Guid NotifySubscriptionID, Guid NotifyDeliveryMethodID)
{
foreach (NotifySubscriptionDelivery child in List)
{
if(child.NotifyDeliveryMethodID==NotifyDeliveryMethodID && child.NotifySubscriptionID == NotifySubscriptionID)
List.Remove(child);
}
}
///
/// Add a new NotifySubscriptionDelivery to the collection
///
///
///
///
public NotifySubscriptionDelivery Add(Guid NotifySubscriptionID, Guid NotifyDeliveryMethodID)
{
NotifySubscriptionDelivery child=NotifySubscriptionDelivery.NewItem(NotifySubscriptionID, NotifyDeliveryMethodID);
List.Add(child);
return child;
}
#endregion
#region Contains
///
///
///
///
///
///
public bool Contains(Guid NotifySubscriptionID, Guid NotifyDeliveryMethodID)
{
foreach (NotifySubscriptionDelivery child in List)
{
if(child.NotifyDeliveryMethodID==NotifyDeliveryMethodID && child.NotifySubscriptionID == NotifySubscriptionID)
return true;
}
return false;
}
///
///
///
///
///
///
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
///
/// NewItems
///
///
internal static NotifySubscriptionDeliveries NewItems()
{
return new NotifySubscriptionDeliveries();
}
///
/// Get items - Grandchild style
///
///
///
internal static NotifySubscriptionDeliveries GetItems(NotifySubscription obj)
{
NotifySubscriptionDeliveries col = new NotifySubscriptionDeliveries();
col.Fetch(obj);
return col;
}
#endregion
#region DAL DATA ACCESS
///
/// Fetch children - grandchild style
///
///
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();
}
}
///
/// Update children
///
///
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
///
/// Given a NotifySubscription item ID deletes all delivery items for that ID
///
/// Called by Subscription delete
///
/// ID of parent NotifySubscription object
/// Database transaction from ascendant item
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