/////////////////////////////////////////////////////////// // 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 { /// /// NotifySubscriber rates collection /// [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 /// /// Retrieve NotifySubscription by index /// /// Index public NotifySubscription this[int Item] { get { return (NotifySubscription) List[Item]; } } /// /// Retrieve NotifySubscription by string containing Guid value /// 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; } } /// /// Remove NotifySubscription by passing it in /// /// public void Remove(NotifySubscription obj) { List.Remove(obj); } /// /// Remove NotifySubscription by string of id value /// /// public void Remove(string NotifySubscriptionID) { System.Guid sid = new System.Guid(NotifySubscriptionID); foreach (NotifySubscription child in List) { if(child.ID==sid) List.Remove(child); } } /// /// Remove by Guid value of ID /// /// public void Remove(Guid NotifySubscriptionID) { foreach (NotifySubscription child in List) { if(child.ID==NotifySubscriptionID) List.Remove(child); } } /// /// Add a new NotifySubscription to the collection /// /// public NotifySubscription Add(NotifySubscriber obj) { NotifySubscription child=NotifySubscription.NewItemChild(obj); List.Add(child); return child; } #endregion #region Contains /// /// Check if item in collection /// by it's event id and root object type /// /// /// /// public bool Contains(RootObjectTypes RootObject, int EventType) { foreach (NotifySubscription child in List) { if(child.RootObjectType== RootObject && child.EventType==EventType) return true; } return false; } /// /// Check if item in collection /// by it's event id, root object type AND GuidValue /// /// /// /// /// 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; } /// /// Check if item in collection by string of ID value /// /// 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; } /// /// Check if item in deleted collection /// /// public bool ContainsDeleted(NotifySubscription obj) { foreach (NotifySubscription child in deletedList) { if(child.Equals(obj)) return true; } return false; } /// /// Check if item in deleted collection by string of ID value /// /// 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 /// /// NewItems /// /// internal static NotifySubscriptions NewItems() { return new NotifySubscriptions(); } /// /// GetItems /// /// /// internal static NotifySubscriptions GetItems(SafeDataReader dr) { NotifySubscriptions col = new NotifySubscriptions(); col.Fetch(dr); return col; } #endregion #region DAL DATA ACCESS /// /// Fetch children /// /// Populated data reader private void Fetch(SafeDataReader dr) { while(dr.Read()) { List.Add(NotifySubscription.GetItemChild(dr)); } } /// /// Update children /// /// /// 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; } /// /// 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 /// /// ID of parent subscriber item /// Database transaction from ascendant item 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