/////////////////////////////////////////////////////////// // UserRights.cs // Implementation of Class UserRights // CSLA type: Editable child collection // Created on: 07-Jun-2004 8:41:43 AM // Object design: Joyce // Coded: John 29-July-2004 /////////////////////////////////////////////////////////// using System; using System.Data; using CSLA.Data; using CSLA; namespace GZTW.AyaNova.BLL { /// /// Editable child collection of objects contained in object /// [Serializable] public class UserRights : BusinessCollectionBase { #region Constructor //Private constructor prevents direction instantiation private UserRights() { //Child MarkAsChild(); AllowSort=false; AllowFind=true; AllowEdit=true; AllowNew=false; AllowRemove=false; } #endregion #region Business properties and methods /// /// Retrieve UserRight by index /// /// Index public UserRight this[int Item] { get { return (UserRight) List[Item]; } } /// /// Retrieve UserRight by string containing Right name value /// public UserRight this[string UserRightName] { get { //System.Guid sid = new System.Guid(UserRightID); foreach (UserRight child in List) { if(child.Right==UserRightName) return child; } return null; } } /// /// Remove UserRight by passing it in /// /// public void Remove(UserRight obj) { List.Remove(obj); } /// /// Remove UserRight by string of id value /// /// public void Remove(string UserRightID) { System.Guid sid = new System.Guid(UserRightID); foreach (UserRight child in List) { if(child.ID==sid) List.Remove(child); } } /// /// Remove by Guid value of ID /// /// public void Remove(Guid UserRightID) { foreach (UserRight child in List) { if(child.ID==UserRightID) List.Remove(child); } } /// /// Add a new UserRight to the collection /// /// public UserRight Add(SecurityGroup obj) { UserRight child=UserRight.NewItem(obj); List.Add(child); return child; } /// /// Add a new UserRight and set it's right name and security level /// to the collection /// /// /// /// /// public UserRight Add(SecurityGroup obj,string sRight, SecurityLevelTypes slt) { UserRight child=UserRight.NewItem(obj); child.Right=sRight; child.SecurityLevel=slt; List.Add(child); return child; } #endregion #region Contains /// /// Check if item in collection /// /// public bool Contains(UserRight obj) { foreach (UserRight child in List) { if(child.Equals(obj)) return true; } return false; } /// /// Check if item in collection by Right name /// /// public bool Contains(string UserRight) { foreach (UserRight child in List) { if(child.Right==UserRight) return true; } return false; } /// /// Check if item in deleted collection /// /// public bool ContainsDeleted(UserRight obj) { foreach (UserRight 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 UserRightID) { System.Guid sid = new System.Guid(UserRightID); foreach (UserRight child in deletedList) { if(child.ID==sid) return true; } return false; } #endregion #region Static methods /// /// NewItems /// /// internal static UserRights NewItems() { return new UserRights(); } /// /// GetItems /// /// /// internal static UserRights GetItems(SafeDataReader dr) { UserRights col = new UserRights(); 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(UserRight.GetItem(dr)); } } /// /// Update children /// /// /// internal void Update(SecurityGroup obj,IDbTransaction tr) { //update (thus deleting) any deleted child objects foreach (UserRight child in deletedList) { child.Update(obj,tr); } //Now that they are deleted remove them from memory deletedList.Clear(); foreach (UserRight child in List) { child.Update(obj,tr); } } #endregion }//end UserRights }//end namespace GZTW.AyaNova.BLL