260 lines
5.5 KiB
C#
260 lines
5.5 KiB
C#
///////////////////////////////////////////////////////////
|
|
// 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
|
|
{
|
|
/// <summary>
|
|
/// Editable child collection of <see cref="UserRight"/> objects contained in <see cref="User"/> object
|
|
/// </summary>
|
|
[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
|
|
/// <summary>
|
|
/// Retrieve UserRight by index
|
|
/// </summary>
|
|
/// <param name="Item">Index</param>
|
|
public UserRight this[int Item]
|
|
{
|
|
get
|
|
{
|
|
return (UserRight) List[Item];
|
|
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Retrieve UserRight by string containing Right name value
|
|
/// </summary>
|
|
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;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Remove UserRight by passing it in
|
|
/// </summary>
|
|
/// <param name="obj"></param>
|
|
public void Remove(UserRight obj)
|
|
{
|
|
List.Remove(obj);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Remove UserRight by string of id value
|
|
/// </summary>
|
|
/// <param name="UserRightID"></param>
|
|
public void Remove(string UserRightID)
|
|
{
|
|
System.Guid sid = new System.Guid(UserRightID);
|
|
foreach (UserRight child in List)
|
|
{
|
|
if(child.ID==sid)
|
|
List.Remove(child);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Remove by Guid value of ID
|
|
/// </summary>
|
|
/// <param name="UserRightID"></param>
|
|
public void Remove(Guid UserRightID)
|
|
{
|
|
foreach (UserRight child in List)
|
|
{
|
|
if(child.ID==UserRightID)
|
|
List.Remove(child);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Add a new UserRight to the collection
|
|
/// </summary>
|
|
/// <param name="obj"></param>
|
|
public UserRight Add(SecurityGroup obj)
|
|
{
|
|
UserRight child=UserRight.NewItem(obj);
|
|
List.Add(child);
|
|
return child;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Add a new UserRight and set it's right name and security level
|
|
/// to the collection
|
|
/// </summary>
|
|
/// <param name="obj"></param>
|
|
/// <param name="sRight"></param>
|
|
/// <param name="slt"></param>
|
|
/// <returns></returns>
|
|
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
|
|
|
|
/// <summary>
|
|
/// Check if item in collection
|
|
/// </summary>
|
|
/// <param name="obj"></param>
|
|
public bool Contains(UserRight obj)
|
|
{
|
|
foreach (UserRight child in List)
|
|
{
|
|
if(child.Equals(obj)) return true;
|
|
}
|
|
return false;
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// Check if item in collection by Right name
|
|
/// </summary>
|
|
/// <param name="UserRight"></param>
|
|
public bool Contains(string UserRight)
|
|
{
|
|
|
|
foreach (UserRight child in List)
|
|
{
|
|
if(child.Right==UserRight) return true;
|
|
}
|
|
return false;
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// Check if item in deleted collection
|
|
/// </summary>
|
|
/// <param name="obj"></param>
|
|
public bool ContainsDeleted(UserRight obj)
|
|
{
|
|
foreach (UserRight 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="UserRightID"></param>
|
|
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
|
|
/// <summary>
|
|
/// NewItems
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
internal static UserRights NewItems()
|
|
{
|
|
return new UserRights();
|
|
}
|
|
|
|
/// <summary>
|
|
/// GetItems
|
|
/// </summary>
|
|
/// <param name="dr"></param>
|
|
/// <returns></returns>
|
|
internal static UserRights GetItems(SafeDataReader dr)
|
|
{
|
|
UserRights col = new UserRights();
|
|
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(UserRight.GetItem(dr));
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Update children
|
|
/// </summary>
|
|
/// <param name="obj"></param>
|
|
/// <param name="tr"></param>
|
|
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 |