// ======================================================================== // Copyright 2006 - Volian Enterprises, Inc. All rights reserved. // Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE // ------------------------------------------------------------------------ // $Workfile: $ $Revision: $ // $Author: $ $Date: $ // // $History: $ // ======================================================================== using System; using System.Data; using System.Data.SqlClient; using Csla; using Csla.Data; using System.Configuration; using System.IO; namespace Volian.CSLA.Library { /// /// RolePermissions Generated by MyGeneration using the CSLA Object Mapping template /// [Serializable()] public partial class RolePermissions : BusinessListBase { #region Business Methods private string _errorMessage = string.Empty; public string ErrorMessage { get { return _errorMessage; } } // One To Many public new RolePermission this[int pid] { get { foreach (RolePermission permission in this) if (permission.PID == pid) return permission; return null; } } public RolePermission GetItem(int pid) { foreach (RolePermission permission in this) if (permission.PID == pid) return permission; return null; } public RolePermission Add(int permLevel, int versionType, int permValue) { RolePermission permission = RolePermission.New(permLevel, versionType, permValue); this.Add(permission); return permission; } public void Remove(int pid) { foreach (RolePermission permission in this) { if (permission.PID == pid) { Remove(permission); break; } } } public bool Contains(int pid) { foreach (RolePermission permission in this) if (permission.PID == pid) return true; return false; } public bool ContainsDeleted(int pid) { foreach (RolePermission permission in DeletedList) if (permission.PID == pid) return true; return false; } #endregion #region Factory Methods internal static RolePermissions New() { return new RolePermissions(); } internal static RolePermissions Get(SafeDataReader dr) { return new RolePermissions(dr); } private RolePermissions() { MarkAsChild(); } private RolePermissions(SafeDataReader dr) { MarkAsChild(); Fetch(dr); } #endregion #region Data Access Portal // called to load data from the database private void Fetch(SafeDataReader dr) { this.RaiseListChangedEvents = false; while (dr.Read()) this.Add(RolePermission.Get(dr)); this.RaiseListChangedEvents = true; } internal void Update(Role role, SqlConnection cn) { this.RaiseListChangedEvents = false; try { // update (thus deleting) any deleted child objects foreach (RolePermission obj in DeletedList) obj.DeleteSelf(role, cn); // now that they are deleted, remove them from memory too DeletedList.Clear(); // add/update any current child objects foreach (RolePermission obj in this) { if (obj.IsNew) obj.Insert(role, cn); else obj.Update(role, cn); } } finally { this.RaiseListChangedEvents = true; } } #endregion } // Class } // Namespace