694 lines
		
	
	
		
			19 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
			
		
		
	
	
			694 lines
		
	
	
		
			19 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>
 | |
| 	///	Role Generated by MyGeneration using the CSLA Object Mapping template
 | |
| 	/// </summary>
 | |
| 	[Serializable()]
 | |
| 	public partial class Role : BusinessBase<Role>
 | |
| 	{
 | |
| 		#region Business Methods
 | |
| 
 | |
| 		private int _rid;
 | |
| 		[System.ComponentModel.DataObjectField(true, true)]
 | |
| 		public int Rid
 | |
| 		{
 | |
| 			[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
 | |
| 			get
 | |
| 			{
 | |
| 				CanReadProperty(true);
 | |
| 				return _rid;
 | |
| 			}
 | |
| 		}
 | |
| 		private string _name=string.Empty;
 | |
| 		[System.ComponentModel.DataObjectField(true, true)]
 | |
| 		public string Name
 | |
| 		{
 | |
| 			[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
 | |
| 			get
 | |
| 			{
 | |
| 				CanReadProperty(true);
 | |
| 				return _name;
 | |
| 			}
 | |
| 			[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
 | |
| 			set
 | |
| 			{
 | |
| 				CanWriteProperty(true);
 | |
| 				if (value == null) value = string.Empty;
 | |
| 				if (_name != value)
 | |
| 				{
 | |
| 					_name = value;
 | |
| 					PropertyHasChanged();
 | |
| 				}
 | |
| 			}
 | |
| 		}
 | |
| 		private string _title=string.Empty;
 | |
| 		[System.ComponentModel.DataObjectField(true, true)]
 | |
| 		public string Title
 | |
| 		{
 | |
| 			[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
 | |
| 			get
 | |
| 			{
 | |
| 				CanReadProperty(true);
 | |
| 				return _title;
 | |
| 			}
 | |
| 			[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
 | |
| 			set
 | |
| 			{
 | |
| 				CanWriteProperty(true);
 | |
| 				if (value == null) value = string.Empty;
 | |
| 				if (_title != value)
 | |
| 				{
 | |
| 					_title = value;
 | |
| 					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 RoleAssignments _roleassignments = RoleAssignments.New();
 | |
| 		/// <summary>
 | |
| 		/// Related Field
 | |
| 		/// </summary>
 | |
| 		[System.ComponentModel.DataObjectField(true, true)]
 | |
| 		public RoleAssignments RoleAssignments
 | |
| 		{
 | |
| 			[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
 | |
| 			get
 | |
| 			{
 | |
| 				CanReadProperty(true);
 | |
| 				return _roleassignments;
 | |
| 			}
 | |
| 		}
 | |
| 		private RolePermissions _rolepermissions = RolePermissions.New();
 | |
| 		/// <summary>
 | |
| 		/// Related Field
 | |
| 		/// </summary>
 | |
| 		[System.ComponentModel.DataObjectField(true, true)]
 | |
| 		public RolePermissions RolePermissions
 | |
| 		{
 | |
| 			[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
 | |
| 			get
 | |
| 			{
 | |
| 				CanReadProperty(true);
 | |
| 				return _rolepermissions;
 | |
| 			}
 | |
| 		}
 | |
| 	    public override bool IsDirty
 | |
| 		{
 | |
| 			get { return base.IsDirty   || _roleassignments.IsDirty  || _rolepermissions.IsDirty ; }
 | |
| 		}
 | |
| 	    public override bool IsValid
 | |
| 		{
 | |
| 			get { return base.IsValid   && _roleassignments.IsValid  && _rolepermissions.IsValid ; }
 | |
| 		}
 | |
| 		// TODO: Replace base Role.ToString function as necessary
 | |
| 		/// <summary>
 | |
| 		/// Overrides Base ToString
 | |
| 		/// </summary>
 | |
| 		/// <returns>A string representation of current Role</returns>
 | |
| 		//public override string ToString()
 | |
| 		//{
 | |
| 		//  return base.ToString();
 | |
| 		//}
 | |
| 
 | |
| 		// TODO: Check Role.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 Role</returns>
 | |
| 		protected override object GetIdValue()
 | |
| 		{
 | |
| 			return _rid;
 | |
| 		}
 | |
| 
 | |
| 		#endregion
 | |
| 
 | |
| 		#region ValidationRules
 | |
| 
 | |
| 		protected override void AddBusinessRules()
 | |
| 		{
 | |
| 			ValidationRules.AddRule(
 | |
| 				Csla.Validation.CommonRules.StringRequired, "Name");
 | |
| 			ValidationRules.AddRule(
 | |
| 				Csla.Validation.CommonRules.StringMaxLength, 
 | |
| 				new Csla.Validation.CommonRules.MaxLengthRuleArgs("Name", 50));
 | |
| 			ValidationRules.AddRule(
 | |
| 				Csla.Validation.CommonRules.StringRequired, "Title");
 | |
| 			ValidationRules.AddRule(
 | |
| 				Csla.Validation.CommonRules.StringMaxLength, 
 | |
| 				new Csla.Validation.CommonRules.MaxLengthRuleArgs("Title", 250));
 | |
| 			ValidationRules.AddRule(
 | |
| 				Csla.Validation.CommonRules.StringMaxLength, 
 | |
| 				new Csla.Validation.CommonRules.MaxLengthRuleArgs("Usrid", 100));
 | |
| 		ext.AddValidationRules(ValidationRules);
 | |
| 		// TODO:  Add other validation rules
 | |
| 		//	ValidationRules.AddRule(StartDateGTEndDate, "Started");
 | |
| 		}
 | |
| 		// 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(Rid, "<Role(s)>");
 | |
| 			//AuthorizationRules.AllowRead(Name, "<Role(s)>");
 | |
| 			//AuthorizationRules.AllowRead(Title, "<Role(s)>");
 | |
| 			//AuthorizationRules.AllowRead(Dts, "<Role(s)>");
 | |
| 			//AuthorizationRules.AllowRead(Usrid, "<Role(s)>");
 | |
| 			//AuthorizationRules.AllowWrite(Name, "<Role(s)>");
 | |
| 			//AuthorizationRules.AllowWrite(Title, "<Role(s)>");
 | |
| 			//AuthorizationRules.AllowWrite(Dts, "<Role(s)>");
 | |
| 			//AuthorizationRules.AllowWrite(Usrid, "<Role(s)>");
 | |
| 			ext.AddAuthorizationRules(AuthorizationRules);
 | |
| 		}
 | |
| 	
 | |
| 		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
 | |
| 		
 | |
| 		private Role()
 | |
| 		{/* require use of factory methods */}
 | |
| 	
 | |
| 		public static Role New()
 | |
| 		{
 | |
| 		  if (!CanAddObject())
 | |
| 			throw new System.Security.SecurityException("User not authorized to add a Role");
 | |
| 		  return DataPortal.Create<Role>();
 | |
| 		}
 | |
| 	
 | |
| 		public static Role Get(int _rid)
 | |
| 		{
 | |
| 		  if (!CanGetObject())
 | |
| 			throw new System.Security.SecurityException("User not authorized to view a Role");
 | |
| 		  return DataPortal.Fetch<Role>(new PKCriteria(_rid));
 | |
| 		}
 | |
| 	
 | |
| 		public static void Delete(int _rid)
 | |
| 		{
 | |
| 			if (!CanDeleteObject())
 | |
| 			throw new System.Security.SecurityException("User not authorized to remove a Role");
 | |
| 		  DataPortal.Delete(new PKCriteria(_rid));
 | |
| 		}
 | |
| 	
 | |
| 		public override Role Save()
 | |
| 		{
 | |
| 		  if (IsDeleted && !CanDeleteObject())
 | |
| 			throw new System.Security.SecurityException("User not authorized to remove a Role");
 | |
| 		  else if (IsNew && !CanAddObject())
 | |
| 			throw new System.Security.SecurityException("User not authorized to add a Role");
 | |
| 		  else if (!CanEditObject())
 | |
| 			throw new System.Security.SecurityException("User not authorized to update a Role");
 | |
| 		  return base.Save();
 | |
| 		}
 | |
| 
 | |
| 		#endregion
 | |
| 
 | |
| 		#region Data Access Portal
 | |
| 
 | |
| 		[Serializable()]
 | |
| 		private class PKCriteria
 | |
| 		{
 | |
| 			private int _rid;
 | |
| 			public int Rid
 | |
| 			{ get {return _rid;}}		
 | |
| 			public PKCriteria(int rid)
 | |
| 			{
 | |
| 				_rid=rid; 
 | |
| 			}
 | |
| 		}
 | |
| 		// If Create needs to access DB - It should not be marked RunLocal
 | |
| 		[RunLocal()]
 | |
| 		private new void DataPortal_Create(object criteria)
 | |
| 		{
 | |
| 		
 | |
| 			// Database Defaults
 | |
| 				_dts = ext.DefaultDts;
 | |
| 				_usrid = ext.DefaultUsrid;
 | |
| 			// TODO: Add any defaults that are necessary
 | |
| 			ValidationRules.CheckRules();
 | |
| 		}
 | |
| 	
 | |
| 		private void DataPortal_Fetch(PKCriteria criteria)
 | |
| 		{
 | |
| 			try{
 | |
| 			using (SqlConnection cn = Database.VEPROMS_SqlConnection)
 | |
| 			{
 | |
| 				using (SqlCommand cm = cn.CreateCommand())
 | |
| 				{
 | |
| 					cm.CommandType = CommandType.StoredProcedure;
 | |
| 					cm.CommandText = "getRole";
 | |
| 					cm.Parameters.AddWithValue("@rID", criteria.Rid);
 | |
| 					using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader()))
 | |
| 					{
 | |
| 						dr.Read();
 | |
| 						_rid = dr.GetInt32("RID");
 | |
| 						_name = dr.GetString("Name");
 | |
| 						_title = dr.GetString("Title");
 | |
| 						_dts = dr.GetDateTime("DTS");
 | |
| 						_usrid = dr.GetString("UsrID");
 | |
| 						dr.GetBytes("LastChanged", 0, _lastchanged, 0, 8);
 | |
| 						// load child objects
 | |
| 						dr.NextResult();
 | |
| 						_roleassignments = RoleAssignments.Get(dr);
 | |
| 
 | |
| 						// load child objects
 | |
| 						dr.NextResult();
 | |
| 						_rolepermissions = RolePermissions.Get(dr);
 | |
| 
 | |
| 					}
 | |
| 				}
 | |
| 			}
 | |
| 		}
 | |
| 		catch(Exception ex)
 | |
| 		{
 | |
| 			Database.LogException("Role",ex);
 | |
| 		}
 | |
| 		}
 | |
| 		[Transactional(TransactionalTypes.TransactionScope)]
 | |
| 		protected override void DataPortal_Insert()
 | |
| 		{
 | |
| 			try{
 | |
| 			using (SqlConnection cn = Database.VEPROMS_SqlConnection)
 | |
| 			{
 | |
| 				using (SqlCommand cm = cn.CreateCommand())
 | |
| 				{
 | |
| 					cm.CommandType = CommandType.StoredProcedure;
 | |
| 					cm.CommandText = "addRole";
 | |
| 					// Input All Fields - Except Calculated Columns
 | |
| 					cm.Parameters.AddWithValue("@name", _name);
 | |
| 					cm.Parameters.AddWithValue("@title", _title);
 | |
| 					cm.Parameters.AddWithValue("@dTS", _dts);
 | |
| 					cm.Parameters.AddWithValue("@usrID", _usrid);
 | |
| 					// Output Calculated Columns
 | |
| 					SqlParameter param_rid = new SqlParameter("@newRID",SqlDbType.Int);
 | |
| 					param_rid.Direction = ParameterDirection.Output;
 | |
| 					cm.Parameters.Add(param_rid);
 | |
| 					SqlParameter param_lastchanged = new SqlParameter("@newLastChanged",SqlDbType.Timestamp);
 | |
| 					param_lastchanged.Direction = ParameterDirection.Output;
 | |
| 					cm.Parameters.Add(param_lastchanged);
 | |
| 					// TODO: Define any additional output parameters
 | |
| 					cm.ExecuteNonQuery();
 | |
| 					// Save all values being returned from the Procedure
 | |
| 					_rid = (int)cm.Parameters["@newRID"].Value;
 | |
| 					_lastchanged = (byte[])cm.Parameters["@newLastChanged"].Value;
 | |
| 			}
 | |
| 		  // update child objects
 | |
| 						_roleassignments.Update(this,cn);
 | |
| 
 | |
| 						_rolepermissions.Update(this,cn);
 | |
| 
 | |
| 				}
 | |
| 				
 | |
| 		}
 | |
| 		catch(Exception ex)
 | |
| 		{
 | |
| 			Database.LogException("Role",ex);
 | |
| 		}}
 | |
| 
 | |
| 		[Transactional(TransactionalTypes.TransactionScope)]
 | |
| 		public static byte[] Add(SqlConnection cn,ref int rid, string name, string title, DateTime dts, string usrid)
 | |
| 		{
 | |
| 			try{
 | |
| 			using (SqlCommand cm = cn.CreateCommand())
 | |
| 			{
 | |
| 				cm.CommandType = CommandType.StoredProcedure;
 | |
| 				cm.CommandText = "addRole";
 | |
| 				// Input All Fields - Except Calculated Columns
 | |
| 
 | |
| 					cm.Parameters.AddWithValue("@name", name);
 | |
| 					cm.Parameters.AddWithValue("@title", title);
 | |
| 					cm.Parameters.AddWithValue("@dTS", dts);
 | |
| 					cm.Parameters.AddWithValue("@usrID", usrid);
 | |
| 				// Output Calculated Columns
 | |
| 			SqlParameter param_rid = new SqlParameter("@newRID",SqlDbType.Int);
 | |
| 			param_rid.Direction = ParameterDirection.Output;
 | |
| 			cm.Parameters.Add(param_rid);
 | |
| 			SqlParameter param_lastchanged = new SqlParameter("@newLastChanged",SqlDbType.Timestamp);
 | |
| 			param_lastchanged.Direction = ParameterDirection.Output;
 | |
| 			cm.Parameters.Add(param_lastchanged);
 | |
| 				// TODO: Define any additional output parameters
 | |
| 				cm.ExecuteNonQuery();
 | |
| 				// Save all values being returned from the Procedure
 | |
| 					rid = (int)cm.Parameters["@newRID"].Value;
 | |
| 			return (byte[])cm.Parameters["@newLastChanged"].Value;
 | |
| 			}
 | |
| 		}
 | |
| 		catch(Exception ex)
 | |
| 		{
 | |
| 			Database.LogException("Role",ex);
 | |
| 			return null;
 | |
| 		}
 | |
| 		}
 | |
| 		[Transactional(TransactionalTypes.TransactionScope)]
 | |
| 		protected override void DataPortal_Update()
 | |
| 		{
 | |
| 			if (IsDirty)// If this is dirty - open the connection
 | |
| 			{
 | |
| 				try{
 | |
| 				using (SqlConnection cn = Database.VEPROMS_SqlConnection)
 | |
| 				{
 | |
| 					if(base.IsDirty)
 | |
| 					{
 | |
| 						using (SqlCommand cm = cn.CreateCommand())
 | |
| 						{
 | |
| 							cm.CommandType = CommandType.StoredProcedure;
 | |
| 							cm.CommandText = "updateRole";
 | |
| 							// All Fields including Calculated Fields
 | |
| 					cm.Parameters.AddWithValue("@rID", _rid);
 | |
| 					cm.Parameters.AddWithValue("@name", _name);
 | |
| 					cm.Parameters.AddWithValue("@title", _title);
 | |
| 					cm.Parameters.AddWithValue("@dTS", _dts);
 | |
| 					cm.Parameters.AddWithValue("@usrID", _usrid);
 | |
| 					cm.Parameters.AddWithValue("@lastChanged", _lastchanged);
 | |
| 					// Output Calculated Columns
 | |
| 					SqlParameter param_lastchanged = new SqlParameter("@newLastChanged",SqlDbType.Timestamp);
 | |
| 					param_lastchanged.Direction = ParameterDirection.Output;
 | |
| 					cm.Parameters.Add(param_lastchanged);
 | |
| 							// TODO: Define any additional output parameters
 | |
| 							cm.ExecuteNonQuery();
 | |
| 							// Save all values being returned from the Procedure
 | |
| 					_lastchanged = (byte[])cm.Parameters["@newLastChanged"].Value;
 | |
| 				}
 | |
| 				}
 | |
| 				// use the open connection to update child objects
 | |
| 						_roleassignments.Update(this,cn);
 | |
| 
 | |
| 						_rolepermissions.Update(this,cn);
 | |
| 
 | |
| 					}
 | |
| 				}
 | |
| 			catch(Exception ex)
 | |
| 			{
 | |
| 				Database.LogException("Role",ex);
 | |
| 			}
 | |
| 			
 | |
| 			}
 | |
| 		}
 | |
| 	
 | |
| 
 | |
| 		[Transactional(TransactionalTypes.TransactionScope)]
 | |
| 		public static byte[] Update(SqlConnection cn,ref int rid, string name, string title, DateTime dts, string usrid, ref byte[] lastchanged)
 | |
| 		{
 | |
| 			try{
 | |
| 			using (SqlCommand cm = cn.CreateCommand())
 | |
| 			{
 | |
| 				cm.CommandType = CommandType.StoredProcedure;
 | |
| 				cm.CommandText = "updateRole";
 | |
| 				// Input All Fields - Except Calculated Columns
 | |
| 
 | |
| 					cm.Parameters.AddWithValue("@rID", rid);
 | |
| 					cm.Parameters.AddWithValue("@name", name);
 | |
| 					cm.Parameters.AddWithValue("@title", title);
 | |
| 					cm.Parameters.AddWithValue("@dTS", dts);
 | |
| 					cm.Parameters.AddWithValue("@usrID", usrid);
 | |
| 					cm.Parameters.AddWithValue("@lastChanged", lastchanged);
 | |
| 				// Output Calculated Columns
 | |
| 			SqlParameter param_lastchanged = new SqlParameter("@newLastChanged",SqlDbType.Timestamp);
 | |
| 			param_lastchanged.Direction = ParameterDirection.Output;
 | |
| 			cm.Parameters.Add(param_lastchanged);
 | |
| 				// TODO: Define any additional output parameters
 | |
| 				cm.ExecuteNonQuery();
 | |
| 				// Save all values being returned from the Procedure
 | |
| 			return (byte[])cm.Parameters["@newLastChanged"].Value;
 | |
| 			}
 | |
| 		}
 | |
| 		catch(Exception ex)
 | |
| 		{
 | |
| 			Database.LogException("Role",ex);
 | |
| 			return null;
 | |
| 		}
 | |
| 		}
 | |
| 		[Transactional(TransactionalTypes.TransactionScope)]
 | |
| 		protected override void DataPortal_DeleteSelf()
 | |
| 		{
 | |
| 		  DataPortal_Delete(new PKCriteria(_rid));
 | |
| 		}
 | |
| 	
 | |
| 
 | |
| 		[Transactional(TransactionalTypes.TransactionScope)]
 | |
| 		private void DataPortal_Delete(PKCriteria criteria)
 | |
| 		{
 | |
| 			try{
 | |
| 			using (SqlConnection cn = Database.VEPROMS_SqlConnection)
 | |
| 			{
 | |
| 				using (SqlCommand cm = cn.CreateCommand())
 | |
| 				{
 | |
| 					cm.CommandType = CommandType.StoredProcedure;
 | |
| 					cm.CommandText = "deleteRole";
 | |
| 					cm.Parameters.AddWithValue("@rID", criteria.Rid);
 | |
| 					cm.ExecuteNonQuery();
 | |
| 				}
 | |
| 			}
 | |
| 		}
 | |
| 		catch(Exception ex)
 | |
| 		{
 | |
| 			Database.LogException("Role",ex);
 | |
| 		}
 | |
| 		}
 | |
| 
 | |
| 		[Transactional(TransactionalTypes.TransactionScope)]
 | |
| 		public static void Remove(SqlConnection cn,int rid)
 | |
| 		{
 | |
| 			try{
 | |
| 			using (SqlCommand cm = cn.CreateCommand())
 | |
| 			{
 | |
| 				cm.CommandType = CommandType.StoredProcedure;
 | |
| 				cm.CommandText = "deleteRole";
 | |
| 				// Input PK Fields
 | |
| 
 | |
| 					cm.Parameters.AddWithValue("@rID", rid);
 | |
| 				// TODO: Define any additional output parameters
 | |
| 				cm.ExecuteNonQuery();
 | |
| 			}
 | |
| 		}
 | |
| 		catch(Exception ex)
 | |
| 		{
 | |
| 			Database.LogException("Role",ex);
 | |
| 		}
 | |
| 		}
 | |
| 
 | |
| 		#endregion
 | |
| 
 | |
| 		#region Exists
 | |
| 
 | |
| 
 | |
|     public static bool Exists(int rid)
 | |
|     {
 | |
|       ExistsCommand result;
 | |
|       result = DataPortal.Execute<ExistsCommand>
 | |
|         (new ExistsCommand(rid));
 | |
|       return result.Exists;
 | |
|     }
 | |
| 
 | |
|     [Serializable()]
 | |
|     private class ExistsCommand : CommandBase
 | |
|     {
 | |
| 
 | |
| 			private int _rid;
 | |
| 		private bool _exists;
 | |
| 
 | |
|       public bool Exists
 | |
|       {
 | |
|         get { return _exists; }
 | |
|       }
 | |
| 
 | |
|       public ExistsCommand(int rid)
 | |
|       {
 | |
| 				_rid=rid;
 | |
| 		}
 | |
| 
 | |
|       protected override void DataPortal_Execute()
 | |
|       {
 | |
| 		try{
 | |
|         using (SqlConnection cn = Database.VEPROMS_SqlConnection)
 | |
|         {
 | |
|           cn.Open();
 | |
|           using (SqlCommand cm = cn.CreateCommand())
 | |
|           {
 | |
|             cm.CommandType = CommandType.StoredProcedure;
 | |
|             cm.CommandText = "existsRole";
 | |
| 
 | |
| 			cm.Parameters.AddWithValue("@rID", _rid);
 | |
| 			int count = (int)cm.ExecuteScalar();
 | |
|             _exists = (count > 0);
 | |
|           }
 | |
|         }
 | |
| 		}
 | |
| 		catch(Exception ex)
 | |
| 		{
 | |
| 			Database.LogException("Role",ex);
 | |
| 		}
 | |
|       }
 | |
|     }
 | |
| 
 | |
| 		#endregion
 | |
| 
 | |
| // Standard Default Code
 | |
| 		//	#region extension
 | |
| 		Extension ext = new Extension();
 | |
| 		[Serializable()]
 | |
| 		partial class Extension : extensionBase
 | |
| 		{
 | |
| 		}
 | |
| 		[Serializable()]
 | |
| 		class extensionBase
 | |
| 		{
 | |
| 			// Default Values
 | |
| 			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 RoleExt.cs
 | |
| //using System;
 | |
| //using System.Collections.Generic;
 | |
| //using System.Text;
 | |
| //using Csla;
 | |
| 
 | |
| //namespace PatrialClass
 | |
| //{
 | |
| //  public partial class Role
 | |
| //  {
 | |
| //    partial class Extension : extensionBase
 | |
| //    {
 | |
| // TODO: Override automatic defaults
 | |
| //			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
 |