/////////////////////////////////////////////////////////// // NotifyDeliverySettings.cs // Implementation of Class NotifyDeliverySettings // CSLA type: Editable root collection // 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; namespace GZTW.AyaNova.BLL { /// /// Editable root collection of objects /// [Serializable] public class NotifyDeliverySettings : BusinessCollectionBase { internal Guid mUserID; #region Constructor //Private constructor prevents direction instantiation private NotifyDeliverySettings() { AllowSort=false; AllowFind=true; AllowEdit=true; AllowNew=true; AllowRemove=true; } #endregion #region Business properties and methods /// /// Locale key so that generic list editor /// UI code knows what title to give the list in a /// grid /// public string LocaleKey { get { return "NotifyDeliverySetting.Label.List"; } } /// /// Retrieve NotifyDeliverySetting by index /// /// Index public NotifyDeliverySetting this[int Item] { get { return (NotifyDeliverySetting) List[Item]; } } /// /// Retrieve NotifyDeliverySetting by Guid value /// public NotifyDeliverySetting this[Guid ID] { get { foreach (NotifyDeliverySetting child in List) { if(child.ID==ID) return child; } return null; } } /// /// Remove NotifyDeliverySetting by passing it in /// /// public void Remove(NotifyDeliverySetting obj) { List.Remove(obj); } /// /// Add a new NotifyDeliverySetting to the collection /// public NotifyDeliverySetting Add() { NotifyDeliverySetting child=NotifyDeliverySetting.NewItem(this.mUserID); List.Add(child); return child; } /// /// Add NotifyDeliverySetting by passing it in /// /// public void Add(NotifyDeliverySetting obj) { List.Add(obj); } /// /// /// /// protected override object OnAddNew() { NotifyDeliverySetting child=NotifyDeliverySetting.NewItem(this.mUserID); List.Add(child); return child; } #endregion #region Contains /// /// Check if item in collection /// /// public bool Contains(NotifyDeliverySetting obj) { foreach (NotifyDeliverySetting child in List) { if(child.Equals(obj)) return true; } return false; } /// /// Check if item in deleted collection /// /// public bool ContainsDeleted(NotifyDeliverySetting obj) { foreach (NotifyDeliverySetting child in deletedList) { if(child.Equals(obj)) return true; } return false; } #endregion #region Static methods /// /// Get item collection /// /// /// public static NotifyDeliverySettings GetItems(Guid UserID) { //in future specify criteria if filtering (e.g. filter by region) NotifyDeliverySettings col = new NotifyDeliverySettings(); return (NotifyDeliverySettings)DataPortal.Fetch(new Criteria(UserID)); } #endregion #region DAL DATA ACCESS /// /// Fetch children /// /// protected override void DataPortal_Fetch(object Criteria) { Criteria crit = (Criteria)Criteria; this.mUserID=crit.UserID; SafeDataReader dr = null; try { if(crit.UserID==Guid.Empty) dr=DBUtil.GetReaderFromSQLString("SELECT * FROM aNotifyDeliverySetting"); else dr=DBUtil.GetReaderFromSQLString("SELECT * FROM aNotifyDeliverySetting WHERE aUserID=@ID",crit.UserID); while(dr.Read()) { List.Add(NotifyDeliverySetting.GetItem(dr)); } } finally { if(dr!=null) dr.Close(); } } /// /// Editable Root Collection Update /// protected override void DataPortal_Update() { using (IDbConnection connection = DBUtil.DB.GetConnection()) { connection.Open(); IDbTransaction tr = connection.BeginTransaction(); try { //update (thus deleting) any deleted child objects foreach (NotifyDeliverySetting child in deletedList) { child.Update(tr); } //Now that they are deleted remove them from memory deletedList.Clear(); foreach (NotifyDeliverySetting child in List) { child.Update(tr); } tr.Commit(); } catch { tr.Rollback(); throw;//WAS: throw(ex); } } } #endregion #region criteria /// /// Criteria for identifying existing object /// [Serializable] private class Criteria { public Guid UserID; public Criteria(Guid _UserID) { UserID=_UserID; } } #endregion }//end NotifyDeliverySettings }//end namespace GZTW.AyaNova.BLL