628 lines
17 KiB
C#
628 lines
17 KiB
C#
|
|
// ========================================================================
|
|
// 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;
|
|
|
|
namespace Volian.Object.Library
|
|
{
|
|
/// <summary>
|
|
/// RoleAssignment Generated by MyGeneration using the CSLA Object Mapping template
|
|
/// </summary>
|
|
[Serializable()]
|
|
public partial class RoleAssignment : BusinessBase<RoleAssignment>
|
|
{
|
|
#region Business Methods
|
|
|
|
|
|
private int _aid;
|
|
[System.ComponentModel.DataObjectField(true, true)]
|
|
public int Aid
|
|
{
|
|
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
|
|
get
|
|
{
|
|
CanReadProperty(true);
|
|
return _aid;
|
|
}
|
|
}
|
|
private int _gid;
|
|
[System.ComponentModel.DataObjectField(true, true)]
|
|
public int Gid
|
|
{
|
|
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
|
|
get
|
|
{
|
|
CanReadProperty(true);
|
|
return _gid;
|
|
}
|
|
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
|
|
set
|
|
{
|
|
CanWriteProperty(true);
|
|
if (_gid != value)
|
|
{
|
|
_gid = value;
|
|
PropertyHasChanged();
|
|
}
|
|
}
|
|
}
|
|
private int _folderid;
|
|
[System.ComponentModel.DataObjectField(true, true)]
|
|
public int Folderid
|
|
{
|
|
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
|
|
get
|
|
{
|
|
CanReadProperty(true);
|
|
return _folderid;
|
|
}
|
|
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
|
|
set
|
|
{
|
|
CanWriteProperty(true);
|
|
if (_folderid != value)
|
|
{
|
|
_folderid = value;
|
|
PropertyHasChanged();
|
|
}
|
|
}
|
|
}
|
|
private string _startdate=string.Empty;
|
|
[System.ComponentModel.DataObjectField(true, true)]
|
|
public string StartDate
|
|
{
|
|
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
|
|
get
|
|
{
|
|
CanReadProperty(true);
|
|
return _startdate;
|
|
}
|
|
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
|
|
set
|
|
{
|
|
CanWriteProperty(true);
|
|
if (value == null) value = string.Empty;
|
|
_startdate = value;
|
|
try
|
|
{
|
|
DateTime tmp = SmartDate.StringToDate(value);
|
|
if (_startdate != tmp.ToShortDateString())
|
|
{
|
|
_startdate = tmp.ToShortDateString();
|
|
// TODO: Any Cross Property Validation
|
|
}
|
|
}
|
|
catch
|
|
{
|
|
}
|
|
PropertyHasChanged();
|
|
}
|
|
}
|
|
private string _enddate=string.Empty;
|
|
[System.ComponentModel.DataObjectField(true, true)]
|
|
public string EndDate
|
|
{
|
|
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
|
|
get
|
|
{
|
|
CanReadProperty(true);
|
|
return _enddate;
|
|
}
|
|
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
|
|
set
|
|
{
|
|
CanWriteProperty(true);
|
|
if (value == null) value = string.Empty;
|
|
_enddate = value;
|
|
try
|
|
{
|
|
DateTime tmp = SmartDate.StringToDate(value);
|
|
if (_enddate != tmp.ToShortDateString())
|
|
{
|
|
_enddate = tmp.ToShortDateString();
|
|
// TODO: Any Cross Property Validation
|
|
}
|
|
}
|
|
catch
|
|
{
|
|
}
|
|
PropertyHasChanged();
|
|
}
|
|
}
|
|
private DateTime _dts=new DateTime();
|
|
[System.ComponentModel.DataObjectField(true, true)]
|
|
public DateTime Dts
|
|
{
|
|
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
|
|
get
|
|
{
|
|
CanReadProperty(true);
|
|
return _dts;
|
|
}
|
|
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
|
|
set
|
|
{
|
|
CanWriteProperty(true);
|
|
if (_dts != value)
|
|
{
|
|
_dts = value;
|
|
PropertyHasChanged();
|
|
}
|
|
}
|
|
}
|
|
private string _usrid=string.Empty;
|
|
[System.ComponentModel.DataObjectField(true, true)]
|
|
public string Usrid
|
|
{
|
|
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
|
|
get
|
|
{
|
|
CanReadProperty(true);
|
|
return _usrid;
|
|
}
|
|
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
|
|
set
|
|
{
|
|
CanWriteProperty(true);
|
|
if (value == null) value = string.Empty;
|
|
if (_usrid != value)
|
|
{
|
|
_usrid = value;
|
|
PropertyHasChanged();
|
|
}
|
|
}
|
|
}
|
|
private byte[] _lastchanged=new byte[8];//timestamp
|
|
private int _folder_parentid;
|
|
[System.ComponentModel.DataObjectField(true, true)]
|
|
public int Folder_Parentid
|
|
{
|
|
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
|
|
get
|
|
{
|
|
CanReadProperty(true);
|
|
return _folder_parentid;
|
|
}
|
|
}
|
|
private int _folder_dbid;
|
|
[System.ComponentModel.DataObjectField(true, true)]
|
|
public int Folder_Dbid
|
|
{
|
|
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
|
|
get
|
|
{
|
|
CanReadProperty(true);
|
|
return _folder_dbid;
|
|
}
|
|
}
|
|
private string _folder_name=string.Empty;
|
|
[System.ComponentModel.DataObjectField(true, true)]
|
|
public string Folder_Name
|
|
{
|
|
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
|
|
get
|
|
{
|
|
CanReadProperty(true);
|
|
return _folder_name;
|
|
}
|
|
}
|
|
private string _folder_title=string.Empty;
|
|
[System.ComponentModel.DataObjectField(true, true)]
|
|
public string Folder_Title
|
|
{
|
|
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
|
|
get
|
|
{
|
|
CanReadProperty(true);
|
|
return _folder_title;
|
|
}
|
|
}
|
|
private string _folder_config=string.Empty;
|
|
[System.ComponentModel.DataObjectField(true, true)]
|
|
public string Folder_Config
|
|
{
|
|
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
|
|
get
|
|
{
|
|
CanReadProperty(true);
|
|
return _folder_config;
|
|
}
|
|
}
|
|
private DateTime _folder_dts=new DateTime();
|
|
[System.ComponentModel.DataObjectField(true, true)]
|
|
public DateTime Folder_Dts
|
|
{
|
|
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
|
|
get
|
|
{
|
|
CanReadProperty(true);
|
|
return _folder_dts;
|
|
}
|
|
}
|
|
private string _folder_usrid=string.Empty;
|
|
[System.ComponentModel.DataObjectField(true, true)]
|
|
public string Folder_Usrid
|
|
{
|
|
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
|
|
get
|
|
{
|
|
CanReadProperty(true);
|
|
return _folder_usrid;
|
|
}
|
|
}
|
|
private string _group_groupname=string.Empty;
|
|
[System.ComponentModel.DataObjectField(true, true)]
|
|
public string Group_GroupName
|
|
{
|
|
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
|
|
get
|
|
{
|
|
CanReadProperty(true);
|
|
return _group_groupname;
|
|
}
|
|
}
|
|
private int _group_grouptype;
|
|
[System.ComponentModel.DataObjectField(true, true)]
|
|
public int Group_GroupType
|
|
{
|
|
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
|
|
get
|
|
{
|
|
CanReadProperty(true);
|
|
return _group_grouptype;
|
|
}
|
|
}
|
|
private string _group_config=string.Empty;
|
|
[System.ComponentModel.DataObjectField(true, true)]
|
|
public string Group_Config
|
|
{
|
|
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
|
|
get
|
|
{
|
|
CanReadProperty(true);
|
|
return _group_config;
|
|
}
|
|
}
|
|
private DateTime _group_dts=new DateTime();
|
|
[System.ComponentModel.DataObjectField(true, true)]
|
|
public DateTime Group_Dts
|
|
{
|
|
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
|
|
get
|
|
{
|
|
CanReadProperty(true);
|
|
return _group_dts;
|
|
}
|
|
}
|
|
private string _group_usrid=string.Empty;
|
|
[System.ComponentModel.DataObjectField(true, true)]
|
|
public string Group_Usrid
|
|
{
|
|
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
|
|
get
|
|
{
|
|
CanReadProperty(true);
|
|
return _group_usrid;
|
|
}
|
|
}
|
|
// TODO: Check RoleAssignment.GetIdValue to assure that the ID returned is unique
|
|
/// <summary>
|
|
/// Overrides Base GetIdValue - Used internally by CSLA to determine equality
|
|
/// </summary>
|
|
/// <returns>A Unique ID for the current RoleAssignment</returns>
|
|
protected override object GetIdValue()
|
|
{
|
|
return _aid;
|
|
}
|
|
// TODO: Replace base RoleAssignment.ToString function as necessary
|
|
/// <summary>
|
|
/// Overrides Base ToString
|
|
/// </summary>
|
|
/// <returns>A string representation of current RoleAssignment</returns>
|
|
//public override string ToString()
|
|
//{
|
|
// return base.ToString();
|
|
//}
|
|
|
|
#endregion
|
|
#region ValidationRules
|
|
|
|
protected override void AddBusinessRules()
|
|
{
|
|
ValidationRules.AddRule(StartDateValid, "StartDate");
|
|
ValidationRules.AddRule(EndDateValid, "EndDate");
|
|
ValidationRules.AddRule(
|
|
Csla.Validation.CommonRules.StringMaxLength,
|
|
new Csla.Validation.CommonRules.MaxLengthRuleArgs("Usrid", 100));
|
|
// TODO: Add other validation rules
|
|
}
|
|
|
|
private bool StartDateValid(object target, Csla.Validation.RuleArgs e)
|
|
{
|
|
try
|
|
{
|
|
DateTime tmp = SmartDate.StringToDate(_startdate);
|
|
}
|
|
catch
|
|
{
|
|
e.Description="Invalid Date";
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
private bool EndDateValid(object target, Csla.Validation.RuleArgs e)
|
|
{
|
|
try
|
|
{
|
|
DateTime tmp = SmartDate.StringToDate(_enddate);
|
|
}
|
|
catch
|
|
{
|
|
e.Description="Invalid Date";
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
// Sample data comparison validation rule
|
|
//private bool StartDateGTEndDate(object target, Csla.Validation.RuleArgs e)
|
|
//{
|
|
// if (_started > _ended)
|
|
// {
|
|
// e.Description = "Start date can't be after end date";
|
|
// return false;
|
|
// }
|
|
// else
|
|
// return true;
|
|
//}
|
|
|
|
#endregion
|
|
|
|
#region Authorization Rules
|
|
protected override void AddAuthorizationRules()
|
|
{
|
|
//TODO: Who can read/write which fields
|
|
//AuthorizationRules.AllowRead(Aid, "<Role(s)>");
|
|
//AuthorizationRules.AllowRead(Gid, "<Role(s)>");
|
|
//AuthorizationRules.AllowWrite(Gid, "<Role(s)>");
|
|
//AuthorizationRules.AllowRead(Folderid, "<Role(s)>");
|
|
//AuthorizationRules.AllowWrite(Folderid, "<Role(s)>");
|
|
//AuthorizationRules.AllowRead(StartDate, "<Role(s)>");
|
|
//AuthorizationRules.AllowWrite(StartDate, "<Role(s)>");
|
|
//AuthorizationRules.AllowRead(EndDate, "<Role(s)>");
|
|
//AuthorizationRules.AllowWrite(EndDate, "<Role(s)>");
|
|
//AuthorizationRules.AllowRead(Dts, "<Role(s)>");
|
|
//AuthorizationRules.AllowWrite(Dts, "<Role(s)>");
|
|
//AuthorizationRules.AllowRead(Usrid, "<Role(s)>");
|
|
//AuthorizationRules.AllowWrite(Usrid, "<Role(s)>");
|
|
}
|
|
|
|
public static bool CanAddObject()
|
|
{
|
|
// TODO: Can Add Authorization
|
|
//return Csla.ApplicationContext.User.IsInRole("ProjectManager");
|
|
return true;
|
|
}
|
|
|
|
public static bool CanGetObject()
|
|
{
|
|
// TODO: CanGet Authorization
|
|
return true;
|
|
}
|
|
|
|
public static bool CanDeleteObject()
|
|
{
|
|
// TODO: CanDelete Authorization
|
|
//bool result = false;
|
|
//if (Csla.ApplicationContext.User.IsInRole("ProjectManager"))result = true;
|
|
//if (Csla.ApplicationContext.User.IsInRole("Administrator"))result = true;
|
|
//return result;
|
|
return true;
|
|
}
|
|
|
|
public static bool CanEditObject()
|
|
{
|
|
// TODO: CanEdit Authorization
|
|
//return Csla.ApplicationContext.User.IsInRole("ProjectManager");
|
|
return true;
|
|
}
|
|
#endregion
|
|
#region Factory Methods
|
|
|
|
internal static RoleAssignment New(int gid, int folderid)
|
|
{
|
|
return new RoleAssignment(Volian.Object.Library.Group.Get(gid), Volian.Object.Library.Folder.Get(folderid));
|
|
}
|
|
|
|
internal static RoleAssignment Get(SafeDataReader dr)
|
|
{
|
|
return new RoleAssignment(dr);
|
|
}
|
|
|
|
private RoleAssignment()
|
|
{
|
|
MarkAsChild();
|
|
_startdate = ext.DefaultStartDate;
|
|
_dts = ext.DefaultDts;
|
|
_usrid = ext.DefaultUsrid;
|
|
}
|
|
|
|
private RoleAssignment(Group group, Folder folder)
|
|
{
|
|
MarkAsChild();
|
|
// TODO: Add any initialization & defaults
|
|
_startdate = ext.DefaultStartDate;
|
|
_dts = ext.DefaultDts;
|
|
_usrid = ext.DefaultUsrid;
|
|
_folderid = folder.Folderid;
|
|
_folder_parentid = folder.Parentid;
|
|
_folder_dbid = folder.Dbid;
|
|
_folder_name = folder.Name;
|
|
_folder_title = folder.Title;
|
|
_folder_config = folder.Config;
|
|
_folder_dts = folder.Dts;
|
|
_folder_usrid = folder.Usrid;
|
|
_gid = group.Gid;
|
|
_group_groupname = group.GroupName;
|
|
_group_grouptype = group.GroupType;
|
|
_group_config = group.Config;
|
|
_group_dts = group.Dts;
|
|
_group_usrid = group.Usrid;
|
|
}
|
|
|
|
private RoleAssignment(SafeDataReader dr)
|
|
{
|
|
MarkAsChild();
|
|
Fetch(dr);
|
|
}
|
|
|
|
|
|
#endregion
|
|
#region Data Access Portal
|
|
|
|
private void Fetch(SafeDataReader dr)
|
|
{
|
|
try{
|
|
_aid = dr.GetInt32("AID");
|
|
_gid = dr.GetInt32("GID");
|
|
_folderid = dr.GetInt32("FolderID");
|
|
_startdate = dr.GetSmartDate("StartDate").Text;
|
|
_enddate = dr.GetSmartDate("EndDate").Text;
|
|
_dts = dr.GetDateTime("DTS");
|
|
_usrid = dr.GetString("UsrID");
|
|
dr.GetBytes("LastChanged", 0, _lastchanged, 0, 8);
|
|
_folder_parentid = dr.GetInt32("Folders_ParentID");
|
|
_folder_dbid = dr.GetInt32("Folders_DBID");
|
|
_folder_name = dr.GetString("Folders_Name");
|
|
_folder_title = dr.GetString("Folders_Title");
|
|
_folder_config = dr.GetString("Folders_Config");
|
|
_folder_dts = dr.GetDateTime("Folders_DTS");
|
|
_folder_usrid = dr.GetString("Folders_UsrID");
|
|
_group_groupname = dr.GetString("Groups_GroupName");
|
|
_group_grouptype = dr.GetInt32("Groups_GroupType");
|
|
_group_config = dr.GetString("Groups_Config");
|
|
_group_dts = dr.GetDateTime("Groups_DTS");
|
|
_group_usrid = dr.GetString("Groups_UsrID");
|
|
}
|
|
catch(Exception ex)
|
|
{
|
|
Database.LogException("RoleAssignment",ex);
|
|
}
|
|
MarkOld();
|
|
}
|
|
|
|
internal void Insert(Role role,SqlConnection cn)
|
|
{
|
|
// if we're not dirty then don't update the database
|
|
if (!this.IsDirty) return;
|
|
_lastchanged=Assignment.Add(cn, ref _aid, _gid, role.Rid, _folderid, new SmartDate(_startdate), new SmartDate(_enddate), _dts, _usrid);
|
|
MarkOld();
|
|
}
|
|
|
|
internal void Update(Role role,SqlConnection cn)
|
|
{
|
|
// if we're not dirty then don't update the database
|
|
if (!this.IsDirty) return;
|
|
_lastchanged=Assignment.Update(cn, ref _aid, _gid, role.Rid, _folderid, new SmartDate(_startdate), new SmartDate(_enddate), _dts, _usrid, ref _lastchanged);
|
|
}
|
|
|
|
internal void DeleteSelf(Role role,SqlConnection cn)
|
|
{
|
|
// if we're not dirty then don't update the database
|
|
if (!this.IsDirty) return;
|
|
// if we're new then don't update the database
|
|
if (this.IsNew) return;
|
|
Assignment.Remove(cn,_aid);
|
|
MarkNew();
|
|
}
|
|
|
|
#endregion
|
|
// Standard Default Code
|
|
// #region extension
|
|
Extension ext = new Extension();
|
|
[Serializable()]
|
|
partial class Extension : extensionBase
|
|
{
|
|
}
|
|
[Serializable()]
|
|
class extensionBase
|
|
{
|
|
// Default Values
|
|
public virtual string DefaultStartDate
|
|
{
|
|
get { return DateTime.Now.ToShortDateString(); }
|
|
}
|
|
public virtual DateTime DefaultDts
|
|
{
|
|
get { return DateTime.Now; }
|
|
}
|
|
public virtual string DefaultUsrid
|
|
{
|
|
get { return Environment.UserName.ToUpper(); }
|
|
}
|
|
// Authorization Rules
|
|
public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules)
|
|
{
|
|
// Needs to be overriden to add new authorization rules
|
|
}
|
|
// Validation Rules
|
|
public virtual void AddValidationRules(Csla.Validation.ValidationRules rules)
|
|
{
|
|
// Needs to be overriden to add new validation rules
|
|
}
|
|
}
|
|
//#endregion
|
|
|
|
// The follwing is a sample Extension File. You can use it to create RoleAssignmentExt.cs
|
|
//using System;
|
|
//using System.Collections.Generic;
|
|
//using System.Text;
|
|
//using Csla;
|
|
|
|
//namespace PatrialClass
|
|
//{
|
|
// public partial class RoleAssignment
|
|
// {
|
|
// partial class Extension : extensionBase
|
|
// {
|
|
// TODO: Override automatic defaults
|
|
// public virtual SmartDate DefaultStartDate
|
|
// {
|
|
// get { return DateTime.Now.ToShortDateString(); }
|
|
// }
|
|
// public virtual DateTime DefaultDts
|
|
// {
|
|
// get { return DateTime.Now; }
|
|
// }
|
|
// public virtual string DefaultUsrid
|
|
// {
|
|
// get { return Environment.UserName.ToUpper(); }
|
|
// }
|
|
// public new void AddAuthorizationRules(Csla.Security.AuthorizationRules rules)
|
|
// {
|
|
// //rules.AllowRead(Dbid, "<Role(s)>");
|
|
// }
|
|
// public new void AddValidationRules(Csla.Validation.ValidationRules rules)
|
|
// {
|
|
// rules.AddRule(
|
|
// Csla.Validation.CommonRules.StringMaxLength,
|
|
// new Csla.Validation.CommonRules.MaxLengthRuleArgs("Name", 100));
|
|
// }
|
|
// }
|
|
// }
|
|
//}
|
|
|
|
} // Class
|
|
} // Namespace
|