332 lines
7.9 KiB
C#
332 lines
7.9 KiB
C#
///////////////////////////////////////////////////////////
|
|
// NotifySubscriptions.cs
|
|
// Implementation of Class NotifySubscriptions
|
|
// CSLA type: Editable child collection
|
|
// Created on: 04-Oct-2005
|
|
// Object design: John
|
|
// Coded: John 04-Oct-2005
|
|
///////////////////////////////////////////////////////////
|
|
|
|
using System;
|
|
using System.Data;
|
|
using CSLA.Data;
|
|
using CSLA;
|
|
|
|
namespace GZTW.AyaNova.BLL
|
|
{
|
|
/// <summary>
|
|
/// NotifySubscriber rates collection
|
|
/// </summary>
|
|
[Serializable]
|
|
public class NotifySubscriptions : BusinessCollectionBase
|
|
{
|
|
|
|
#region Constructor
|
|
|
|
//Private constructor prevents direction instantiation
|
|
private NotifySubscriptions()
|
|
{
|
|
//Child
|
|
MarkAsChild();
|
|
AllowSort=false;
|
|
AllowFind=true;
|
|
AllowEdit=true;
|
|
AllowNew=true;
|
|
AllowRemove=true;
|
|
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Business properties and methods
|
|
/// <summary>
|
|
/// Retrieve NotifySubscription by index
|
|
/// </summary>
|
|
/// <param name="Item">Index</param>
|
|
public NotifySubscription this[int Item]
|
|
{
|
|
get
|
|
{
|
|
return (NotifySubscription) List[Item];
|
|
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Retrieve NotifySubscription by string containing Guid value
|
|
/// </summary>
|
|
public NotifySubscription this[string NotifySubscriptionID]
|
|
{
|
|
get
|
|
{
|
|
System.Guid sid = new System.Guid(NotifySubscriptionID);
|
|
foreach (NotifySubscription child in List)
|
|
{
|
|
if(child.ID==sid)
|
|
return child;
|
|
}
|
|
return null;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Remove NotifySubscription by passing it in
|
|
/// </summary>
|
|
/// <param name="obj"></param>
|
|
public void Remove(NotifySubscription obj)
|
|
{
|
|
List.Remove(obj);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Remove NotifySubscription by string of id value
|
|
/// </summary>
|
|
/// <param name="NotifySubscriptionID"></param>
|
|
public void Remove(string NotifySubscriptionID)
|
|
{
|
|
System.Guid sid = new System.Guid(NotifySubscriptionID);
|
|
foreach (NotifySubscription child in List)
|
|
{
|
|
if(child.ID==sid)
|
|
List.Remove(child);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Remove by Guid value of ID
|
|
/// </summary>
|
|
/// <param name="NotifySubscriptionID"></param>
|
|
public void Remove(Guid NotifySubscriptionID)
|
|
{
|
|
foreach (NotifySubscription child in List)
|
|
{
|
|
if(child.ID==NotifySubscriptionID)
|
|
List.Remove(child);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Add a new NotifySubscription to the collection
|
|
/// </summary>
|
|
/// <param name="obj"></param>
|
|
public NotifySubscription Add(NotifySubscriber obj)
|
|
{
|
|
NotifySubscription child=NotifySubscription.NewItemChild(obj);
|
|
List.Add(child);
|
|
return child;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Contains
|
|
|
|
/// <summary>
|
|
/// Check if item in collection
|
|
/// by it's event id and root object type
|
|
/// </summary>
|
|
/// <param name="RootObject"></param>
|
|
/// <param name="EventType"></param>
|
|
/// <returns></returns>
|
|
public bool Contains(RootObjectTypes RootObject, int EventType)
|
|
{
|
|
foreach (NotifySubscription child in List)
|
|
{
|
|
if(child.RootObjectType== RootObject && child.EventType==EventType) return true;
|
|
}
|
|
return false;
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// Check if item in collection
|
|
/// by it's event id, root object type AND GuidValue
|
|
/// </summary>
|
|
/// <param name="RootObject"></param>
|
|
/// <param name="EventType"></param>
|
|
/// <param name="GuidValue"></param>
|
|
/// <returns></returns>
|
|
public bool Contains(RootObjectTypes RootObject, int EventType, Guid GuidValue)
|
|
{
|
|
foreach (NotifySubscription child in List)
|
|
{
|
|
if(child.RootObjectType== RootObject && child.EventType==EventType && child.GuidValue==GuidValue) return true;
|
|
}
|
|
return false;
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// Check if item in collection by string of ID value
|
|
/// </summary>
|
|
/// <param name="NotifySubscriptionID"></param>
|
|
public bool Contains(string NotifySubscriptionID)
|
|
{
|
|
System.Guid sid = new System.Guid(NotifySubscriptionID);
|
|
foreach (NotifySubscription child in List)
|
|
{
|
|
if(child.ID==sid) return true;
|
|
}
|
|
return false;
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// Check if item in deleted collection
|
|
/// </summary>
|
|
/// <param name="obj"></param>
|
|
public bool ContainsDeleted(NotifySubscription obj)
|
|
{
|
|
foreach (NotifySubscription child in deletedList)
|
|
{
|
|
if(child.Equals(obj)) return true;
|
|
}
|
|
return false;
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// Check if item in deleted collection by string of ID value
|
|
/// </summary>
|
|
/// <param name="NotifySubscriptionID"></param>
|
|
public bool ContainsDeleted(string NotifySubscriptionID)
|
|
{
|
|
System.Guid sid = new System.Guid(NotifySubscriptionID);
|
|
foreach (NotifySubscription child in deletedList)
|
|
{
|
|
if(child.ID==sid) return true;
|
|
}
|
|
return false;
|
|
|
|
}
|
|
#endregion
|
|
|
|
#region Static methods
|
|
/// <summary>
|
|
/// NewItems
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
internal static NotifySubscriptions NewItems()
|
|
{
|
|
return new NotifySubscriptions();
|
|
}
|
|
|
|
/// <summary>
|
|
/// GetItems
|
|
/// </summary>
|
|
/// <param name="dr"></param>
|
|
/// <returns></returns>
|
|
internal static NotifySubscriptions GetItems(SafeDataReader dr)
|
|
{
|
|
NotifySubscriptions col = new NotifySubscriptions();
|
|
col.Fetch(dr);
|
|
return col;
|
|
}
|
|
#endregion
|
|
|
|
#region DAL DATA ACCESS
|
|
|
|
/// <summary>
|
|
/// Fetch children
|
|
/// </summary>
|
|
/// <param name="dr">Populated data reader</param>
|
|
private void Fetch(SafeDataReader dr)
|
|
{
|
|
while(dr.Read())
|
|
{
|
|
List.Add(NotifySubscription.GetItemChild(dr));
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Update children
|
|
/// </summary>
|
|
/// <param name="obj"></param>
|
|
/// <param name="tr"></param>
|
|
internal void Update(NotifySubscriber obj,IDbTransaction tr)
|
|
{
|
|
//update (thus deleting) any deleted child objects
|
|
foreach (NotifySubscription child in deletedList)
|
|
{
|
|
child.Update(obj,tr);
|
|
}
|
|
|
|
//Now that they are deleted remove them from memory
|
|
deletedList.Clear();
|
|
|
|
foreach (NotifySubscription child in List)
|
|
{
|
|
child.Update(obj,tr);
|
|
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region Shared delete method
|
|
internal struct nsub
|
|
{
|
|
public Guid id;
|
|
public RootObjectTypes rotype;
|
|
public int eventtype;
|
|
public Guid guidvalue;
|
|
|
|
}
|
|
/// <summary>
|
|
/// Given a Subscriber ID
|
|
///
|
|
/// retrieves all Subscription id values for that
|
|
/// subscriber, then calls the subscription Shared static direct
|
|
/// delete method to clear out those subscriptions
|
|
///
|
|
/// This is done this way to handle updating the notifyeventofinterest table
|
|
/// properly on deletion
|
|
///
|
|
/// Called by subscriber delete
|
|
/// </summary>
|
|
/// <param name="SubscriberID">ID of parent subscriber item</param>
|
|
/// <param name="transaction">Database transaction from ascendant item</param>
|
|
internal static void DeleteItems(Guid SubscriberID,IDbTransaction transaction)
|
|
{
|
|
|
|
//This one is more tricky, here we need to iterate through all the matching records
|
|
//and call the static delete method
|
|
System.Collections.ArrayList al=new System.Collections.ArrayList();
|
|
SafeDataReader dr = null;
|
|
|
|
|
|
|
|
try
|
|
{
|
|
dr=DBUtil.GetReaderFromSQLString("SELECT aID, aRootObjectType, aEventType, aGuidValue " +
|
|
"FROM aNotifySubscription " +
|
|
"WHERE aUserID=@ID",SubscriberID);
|
|
while(dr.Read())
|
|
{
|
|
nsub n=new nsub();
|
|
n.id=dr.GetGuid("aID");
|
|
n.rotype=(RootObjectTypes)dr.GetInt16("aRootObjectType");
|
|
n.eventtype=dr.GetInt16("aEventType");
|
|
n.guidvalue=dr.GetGuid("aGuidValue");
|
|
al.Add(n);
|
|
|
|
|
|
}
|
|
dr.Close();
|
|
|
|
foreach(object o in al)
|
|
{
|
|
nsub n1=(nsub)o;
|
|
NotifySubscription.DeleteItem(n1.id,n1.rotype,n1.eventtype,n1.guidvalue,SubscriberID,transaction);
|
|
|
|
}
|
|
}
|
|
finally
|
|
{
|
|
if(dr!=null) dr.Close();
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
}//end NotifySubscriptions
|
|
|
|
}//end namespace GZTW.AyaNova.BLL |