CSLA - R to Z
This commit is contained in:
@@ -13,8 +13,6 @@ using System.Data;
|
||||
using System.Data.SqlClient;
|
||||
using Csla;
|
||||
using Csla.Data;
|
||||
using System.Configuration;
|
||||
using System.IO;
|
||||
using System.ComponentModel;
|
||||
using System.Collections.Generic;
|
||||
using Csla.Validation;
|
||||
@@ -37,10 +35,7 @@ namespace VEPROMS.CSLA.Library
|
||||
if (IsDirty)
|
||||
refreshSessions.Add(this);
|
||||
}
|
||||
private void ClearRefreshList()
|
||||
{
|
||||
_RefreshSessions = new List<Session>();
|
||||
}
|
||||
private void ClearRefreshList() => _RefreshSessions = new List<Session>();
|
||||
private void BuildRefreshList()
|
||||
{
|
||||
ClearRefreshList();
|
||||
@@ -56,6 +51,7 @@ namespace VEPROMS.CSLA.Library
|
||||
}
|
||||
#endregion
|
||||
#region Collection
|
||||
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "Keeping Collections Not ReadOnly")]
|
||||
private static List<Session> _CacheList = new List<Session>();
|
||||
protected static void AddToCache(Session session)
|
||||
{
|
||||
@@ -65,6 +61,7 @@ namespace VEPROMS.CSLA.Library
|
||||
{
|
||||
while (_CacheList.Contains(session)) _CacheList.Remove(session); // In RemoveFromCache
|
||||
}
|
||||
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "Keeping Collections Not ReadOnly")]
|
||||
private static Dictionary<string, List<Session>> _CacheByPrimaryKey = new Dictionary<string, List<Session>>();
|
||||
private static void ConvertListToDictionary()
|
||||
{
|
||||
@@ -90,15 +87,9 @@ namespace VEPROMS.CSLA.Library
|
||||
#endregion
|
||||
#region Business Methods
|
||||
private string _ErrorMessage = string.Empty;
|
||||
public string ErrorMessage
|
||||
{
|
||||
get { return _ErrorMessage; }
|
||||
}
|
||||
public string ErrorMessage => _ErrorMessage;
|
||||
private static int _nextSessionID = -1;
|
||||
public static int NextSessionID
|
||||
{
|
||||
get { return _nextSessionID--; }
|
||||
}
|
||||
public static int NextSessionID => _nextSessionID--;
|
||||
private int _SessionID;
|
||||
[System.ComponentModel.DataObjectField(true, true)]
|
||||
public int SessionID
|
||||
@@ -220,40 +211,14 @@ namespace VEPROMS.CSLA.Library
|
||||
}
|
||||
}
|
||||
}
|
||||
public override bool IsDirty
|
||||
{
|
||||
get { return base.IsDirty; }
|
||||
}
|
||||
public bool IsDirtyList(List<object> list)
|
||||
{
|
||||
return base.IsDirty;
|
||||
}
|
||||
public override bool IsValid
|
||||
{
|
||||
get { return (IsNew && !IsDirty) ? true : base.IsValid; }
|
||||
}
|
||||
public bool IsValidList(List<object> list)
|
||||
{
|
||||
return (IsNew && !IsDirty) ? true : base.IsValid;
|
||||
}
|
||||
// CSLATODO: Replace base Session.ToString function as necessary
|
||||
/// <summary>
|
||||
/// Overrides Base ToString
|
||||
/// </summary>
|
||||
/// <returns>A string representation of current Session</returns>
|
||||
//public override string ToString()
|
||||
//{
|
||||
// return base.ToString();
|
||||
//}
|
||||
public override bool IsDirty => base.IsDirty;
|
||||
public override bool IsValid => (IsNew && !IsDirty) || base.IsValid;
|
||||
// CSLATODO: Check Session.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 Session</returns>
|
||||
protected override object GetIdValue()
|
||||
{
|
||||
return MySessionUnique; // Absolutely Unique ID
|
||||
}
|
||||
protected override object GetIdValue() => MySessionUnique; // Absolutely Unique ID
|
||||
#endregion
|
||||
#region ValidationRules
|
||||
[NonSerialized]
|
||||
@@ -281,8 +246,8 @@ namespace VEPROMS.CSLA.Library
|
||||
get
|
||||
{
|
||||
IVEHasBrokenRules hasBrokenRules = HasBrokenRules;
|
||||
if (this.Equals(hasBrokenRules)) return BrokenRulesCollection;
|
||||
return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null);
|
||||
if (Equals(hasBrokenRules)) return BrokenRulesCollection;
|
||||
return hasBrokenRules?.BrokenRules;
|
||||
}
|
||||
}
|
||||
protected override void AddBusinessRules()
|
||||
@@ -306,35 +271,11 @@ namespace VEPROMS.CSLA.Library
|
||||
_SessionExtension.AddInstanceValidationRules(ValidationRules);
|
||||
// CSLATODO: Add other validation rules
|
||||
}
|
||||
// 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()
|
||||
{
|
||||
//CSLATODO: Who can read/write which fields
|
||||
//AuthorizationRules.AllowRead(SessionID, "<Role(s)>");
|
||||
//AuthorizationRules.AllowRead(UserID, "<Role(s)>");
|
||||
//AuthorizationRules.AllowRead(DTSDtart, "<Role(s)>");
|
||||
//AuthorizationRules.AllowRead(DTSEnd, "<Role(s)>");
|
||||
//AuthorizationRules.AllowRead(DTSActivity, "<Role(s)>");
|
||||
//AuthorizationRules.AllowRead(MachineName, "<Role(s)>");
|
||||
//AuthorizationRules.AllowRead(ProcessID, "<Role(s)>");
|
||||
//AuthorizationRules.AllowWrite(UserID, "<Role(s)>");
|
||||
//AuthorizationRules.AllowWrite(DTSDtart, "<Role(s)>");
|
||||
//AuthorizationRules.AllowWrite(DTSEnd, "<Role(s)>");
|
||||
//AuthorizationRules.AllowWrite(DTSActivity, "<Role(s)>");
|
||||
//AuthorizationRules.AllowWrite(MachineName, "<Role(s)>");
|
||||
//AuthorizationRules.AllowWrite(ProcessID, "<Role(s)>");
|
||||
_SessionExtension.AddAuthorizationRules(AuthorizationRules);
|
||||
}
|
||||
protected override void AddInstanceAuthorizationRules()
|
||||
@@ -342,42 +283,14 @@ namespace VEPROMS.CSLA.Library
|
||||
//CSLATODO: Who can read/write which fields
|
||||
_SessionExtension.AddInstanceAuthorizationRules(AuthorizationRules);
|
||||
}
|
||||
public static bool CanAddObject()
|
||||
{
|
||||
// CSLATODO: Can Add Authorization
|
||||
//return Csla.ApplicationContext.User.IsInRole("ProjectManager");
|
||||
return true;
|
||||
}
|
||||
public static bool CanGetObject()
|
||||
{
|
||||
// CSLATODO: CanGet Authorization
|
||||
return true;
|
||||
}
|
||||
public static bool CanDeleteObject()
|
||||
{
|
||||
// CSLATODO: 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()
|
||||
{
|
||||
// CSLATODO: CanEdit Authorization
|
||||
//return Csla.ApplicationContext.User.IsInRole("ProjectManager");
|
||||
return true;
|
||||
}
|
||||
#endregion
|
||||
#region Factory Methods
|
||||
public int CurrentEditLevel
|
||||
{ get { return EditLevel; } }
|
||||
public int CurrentEditLevel => EditLevel;
|
||||
private static int _SessionUnique = 0;
|
||||
protected static int SessionUnique
|
||||
{ get { return ++_SessionUnique; } }
|
||||
private int _MySessionUnique = SessionUnique;
|
||||
public int MySessionUnique // Absolutely Unique ID - Editable
|
||||
{ get { return _MySessionUnique; } }
|
||||
protected static int SessionUnique => ++_SessionUnique;
|
||||
private readonly int _MySessionUnique = SessionUnique;
|
||||
// Absolutely Unique ID - Editable
|
||||
public int MySessionUnique => _MySessionUnique;
|
||||
protected Session()
|
||||
{/* require use of factory methods */
|
||||
AddToCache(this);
|
||||
@@ -386,15 +299,11 @@ namespace VEPROMS.CSLA.Library
|
||||
private static int _CountCreated = 0;
|
||||
private static int _CountDisposed = 0;
|
||||
private static int _CountFinalized = 0;
|
||||
private static int IncrementCountCreated
|
||||
{ get { return ++_CountCreated; } }
|
||||
private int _CountWhenCreated = IncrementCountCreated;
|
||||
public static int CountCreated
|
||||
{ get { return _CountCreated; } }
|
||||
public static int CountNotDisposed
|
||||
{ get { return _CountCreated - _CountDisposed; } }
|
||||
public static int CountNotFinalized
|
||||
{ get { return _CountCreated - _CountFinalized; } }
|
||||
private static int IncrementCountCreated => ++_CountCreated;
|
||||
private readonly int _CountWhenCreated = IncrementCountCreated;
|
||||
public static int CountCreated => _CountCreated;
|
||||
public static int CountNotDisposed => _CountCreated - _CountDisposed;
|
||||
public static int CountNotFinalized => _CountCreated - _CountFinalized;
|
||||
~Session()
|
||||
{
|
||||
_CountFinalized++;
|
||||
@@ -419,8 +328,6 @@ namespace VEPROMS.CSLA.Library
|
||||
}
|
||||
public static Session New()
|
||||
{
|
||||
if (!CanAddObject())
|
||||
throw new System.Security.SecurityException("User not authorized to add a Session");
|
||||
try
|
||||
{
|
||||
return DataPortal.Create<Session>();
|
||||
@@ -490,8 +397,6 @@ namespace VEPROMS.CSLA.Library
|
||||
}
|
||||
public static Session Get(int sessionID)
|
||||
{
|
||||
if (!CanGetObject())
|
||||
throw new System.Security.SecurityException("User not authorized to view a Session");
|
||||
try
|
||||
{
|
||||
Session tmp = GetCachedByPrimaryKey(sessionID);
|
||||
@@ -512,19 +417,10 @@ namespace VEPROMS.CSLA.Library
|
||||
throw new DbCslaException("Error on Session.Get", ex);
|
||||
}
|
||||
}
|
||||
public static Session Get(SafeDataReader dr)
|
||||
{
|
||||
if (dr.Read()) return new Session(dr);
|
||||
return null;
|
||||
}
|
||||
internal Session(SafeDataReader dr)
|
||||
{
|
||||
ReadData(dr);
|
||||
}
|
||||
public static Session Get(SafeDataReader dr) => dr.Read() ? new Session(dr) : null;
|
||||
internal Session(SafeDataReader dr) => ReadData(dr);
|
||||
public static void Delete(int sessionID)
|
||||
{
|
||||
if (!CanDeleteObject())
|
||||
throw new System.Security.SecurityException("User not authorized to remove a Session");
|
||||
try
|
||||
{
|
||||
DataPortal.Delete(new PKCriteria(sessionID));
|
||||
@@ -536,12 +432,6 @@ namespace VEPROMS.CSLA.Library
|
||||
}
|
||||
public override Session Save()
|
||||
{
|
||||
if (IsDeleted && !CanDeleteObject())
|
||||
throw new System.Security.SecurityException("User not authorized to remove a Session");
|
||||
else if (IsNew && !CanAddObject())
|
||||
throw new System.Security.SecurityException("User not authorized to add a Session");
|
||||
else if (!CanEditObject())
|
||||
throw new System.Security.SecurityException("User not authorized to update a Session");
|
||||
try
|
||||
{
|
||||
BuildRefreshList();
|
||||
@@ -561,13 +451,9 @@ namespace VEPROMS.CSLA.Library
|
||||
[Serializable()]
|
||||
protected class PKCriteria
|
||||
{
|
||||
private int _SessionID;
|
||||
public int SessionID
|
||||
{ get { return _SessionID; } }
|
||||
public PKCriteria(int sessionID)
|
||||
{
|
||||
_SessionID = sessionID;
|
||||
}
|
||||
private readonly int _SessionID;
|
||||
public int SessionID => _SessionID;
|
||||
public PKCriteria(int sessionID) => _SessionID = sessionID;
|
||||
}
|
||||
// CSLATODO: If Create needs to access DB - It should not be marked RunLocal
|
||||
[RunLocal()]
|
||||
@@ -667,35 +553,42 @@ namespace VEPROMS.CSLA.Library
|
||||
[Transactional(TransactionalTypes.TransactionScope)]
|
||||
internal void SQLInsert()
|
||||
{
|
||||
if (!this.IsDirty) return;
|
||||
if (!IsDirty) return;
|
||||
try
|
||||
{
|
||||
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"];
|
||||
using (SqlCommand cm = cn.CreateCommand())
|
||||
using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"])
|
||||
{
|
||||
cm.CommandType = CommandType.StoredProcedure;
|
||||
cm.CommandTimeout = Database.SQLTimeout;
|
||||
cm.CommandText = "addSession";
|
||||
// Input All Fields - Except Calculated Columns
|
||||
cm.Parameters.AddWithValue("@UserID", _UserID);
|
||||
if (_DTSDtart.Year >= 1753 && _DTSDtart.Year <= 9999) cm.Parameters.AddWithValue("@DTSDtart", _DTSDtart);
|
||||
if (_DTSEnd != null && ((DateTime)_DTSEnd).Year >= 1753 && ((DateTime)_DTSEnd).Year <= 9999) cm.Parameters.AddWithValue("@DTSEnd", _DTSEnd);
|
||||
if (_DTSActivity.Year >= 1753 && _DTSActivity.Year <= 9999) cm.Parameters.AddWithValue("@DTSActivity", _DTSActivity);
|
||||
cm.Parameters.AddWithValue("@MachineName", _MachineName);
|
||||
cm.Parameters.AddWithValue("@ProcessID", _ProcessID);
|
||||
// Output Calculated Columns
|
||||
SqlParameter param_SessionID = new SqlParameter("@newSessionID", SqlDbType.Int);
|
||||
param_SessionID.Direction = ParameterDirection.Output;
|
||||
cm.Parameters.Add(param_SessionID);
|
||||
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp);
|
||||
param_LastChanged.Direction = ParameterDirection.Output;
|
||||
cm.Parameters.Add(param_LastChanged);
|
||||
// CSLATODO: Define any additional output parameters
|
||||
cm.ExecuteNonQuery();
|
||||
// Save all values being returned from the Procedure
|
||||
_SessionID = (int)cm.Parameters["@newSessionID"].Value;
|
||||
_LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value;
|
||||
using (SqlCommand cm = cn.CreateCommand())
|
||||
{
|
||||
cm.CommandType = CommandType.StoredProcedure;
|
||||
cm.CommandTimeout = Database.SQLTimeout;
|
||||
cm.CommandText = "addSession";
|
||||
// Input All Fields - Except Calculated Columns
|
||||
cm.Parameters.AddWithValue("@UserID", _UserID);
|
||||
if (_DTSDtart.Year >= 1753 && _DTSDtart.Year <= 9999) cm.Parameters.AddWithValue("@DTSDtart", _DTSDtart);
|
||||
if (_DTSEnd != null && ((DateTime)_DTSEnd).Year >= 1753 && ((DateTime)_DTSEnd).Year <= 9999) cm.Parameters.AddWithValue("@DTSEnd", _DTSEnd);
|
||||
if (_DTSActivity.Year >= 1753 && _DTSActivity.Year <= 9999) cm.Parameters.AddWithValue("@DTSActivity", _DTSActivity);
|
||||
cm.Parameters.AddWithValue("@MachineName", _MachineName);
|
||||
cm.Parameters.AddWithValue("@ProcessID", _ProcessID);
|
||||
// Output Calculated Columns
|
||||
SqlParameter param_SessionID = new SqlParameter("@newSessionID", SqlDbType.Int)
|
||||
{
|
||||
Direction = ParameterDirection.Output
|
||||
};
|
||||
cm.Parameters.Add(param_SessionID);
|
||||
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp)
|
||||
{
|
||||
Direction = ParameterDirection.Output
|
||||
};
|
||||
cm.Parameters.Add(param_LastChanged);
|
||||
// CSLATODO: Define any additional output parameters
|
||||
cm.ExecuteNonQuery();
|
||||
// Save all values being returned from the Procedure
|
||||
_SessionID = (int)cm.Parameters["@newSessionID"].Value;
|
||||
_LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value;
|
||||
}
|
||||
}
|
||||
|
||||
MarkOld();
|
||||
// update child objects
|
||||
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Session.SQLInsert", GetHashCode());
|
||||
@@ -726,11 +619,15 @@ namespace VEPROMS.CSLA.Library
|
||||
cm.Parameters.AddWithValue("@MachineName", machineName);
|
||||
cm.Parameters.AddWithValue("@ProcessID", processID);
|
||||
// Output Calculated Columns
|
||||
SqlParameter param_SessionID = new SqlParameter("@newSessionID", SqlDbType.Int);
|
||||
param_SessionID.Direction = ParameterDirection.Output;
|
||||
SqlParameter param_SessionID = new SqlParameter("@newSessionID", SqlDbType.Int)
|
||||
{
|
||||
Direction = ParameterDirection.Output
|
||||
};
|
||||
cm.Parameters.Add(param_SessionID);
|
||||
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp);
|
||||
param_LastChanged.Direction = ParameterDirection.Output;
|
||||
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp)
|
||||
{
|
||||
Direction = ParameterDirection.Output
|
||||
};
|
||||
cm.Parameters.Add(param_LastChanged);
|
||||
// CSLATODO: Define any additional output parameters
|
||||
cm.ExecuteNonQuery();
|
||||
@@ -775,33 +672,38 @@ namespace VEPROMS.CSLA.Library
|
||||
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Session.SQLUpdate", GetHashCode());
|
||||
try
|
||||
{
|
||||
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"];
|
||||
if (base.IsDirty)
|
||||
using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"])
|
||||
{
|
||||
using (SqlCommand cm = cn.CreateCommand())
|
||||
if (base.IsDirty)
|
||||
{
|
||||
cm.CommandType = CommandType.StoredProcedure;
|
||||
cm.CommandTimeout = Database.SQLTimeout;
|
||||
cm.CommandText = "updateSession";
|
||||
// All Fields including Calculated Fields
|
||||
cm.Parameters.AddWithValue("@SessionID", _SessionID);
|
||||
cm.Parameters.AddWithValue("@UserID", _UserID);
|
||||
if (_DTSDtart.Year >= 1753 && _DTSDtart.Year <= 9999) cm.Parameters.AddWithValue("@DTSDtart", _DTSDtart);
|
||||
if (_DTSEnd != null && ((DateTime)_DTSEnd).Year >= 1753 && ((DateTime)_DTSEnd).Year <= 9999) cm.Parameters.AddWithValue("@DTSEnd", _DTSEnd);
|
||||
if (_DTSActivity.Year >= 1753 && _DTSActivity.Year <= 9999) cm.Parameters.AddWithValue("@DTSActivity", _DTSActivity);
|
||||
cm.Parameters.AddWithValue("@LastChanged", _LastChanged);
|
||||
cm.Parameters.AddWithValue("@MachineName", _MachineName);
|
||||
cm.Parameters.AddWithValue("@ProcessID", _ProcessID);
|
||||
// Output Calculated Columns
|
||||
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp);
|
||||
param_LastChanged.Direction = ParameterDirection.Output;
|
||||
cm.Parameters.Add(param_LastChanged);
|
||||
// CSLATODO: Define any additional output parameters
|
||||
cm.ExecuteNonQuery();
|
||||
// Save all values being returned from the Procedure
|
||||
_LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value;
|
||||
using (SqlCommand cm = cn.CreateCommand())
|
||||
{
|
||||
cm.CommandType = CommandType.StoredProcedure;
|
||||
cm.CommandTimeout = Database.SQLTimeout;
|
||||
cm.CommandText = "updateSession";
|
||||
// All Fields including Calculated Fields
|
||||
cm.Parameters.AddWithValue("@SessionID", _SessionID);
|
||||
cm.Parameters.AddWithValue("@UserID", _UserID);
|
||||
if (_DTSDtart.Year >= 1753 && _DTSDtart.Year <= 9999) cm.Parameters.AddWithValue("@DTSDtart", _DTSDtart);
|
||||
if (_DTSEnd != null && ((DateTime)_DTSEnd).Year >= 1753 && ((DateTime)_DTSEnd).Year <= 9999) cm.Parameters.AddWithValue("@DTSEnd", _DTSEnd);
|
||||
if (_DTSActivity.Year >= 1753 && _DTSActivity.Year <= 9999) cm.Parameters.AddWithValue("@DTSActivity", _DTSActivity);
|
||||
cm.Parameters.AddWithValue("@LastChanged", _LastChanged);
|
||||
cm.Parameters.AddWithValue("@MachineName", _MachineName);
|
||||
cm.Parameters.AddWithValue("@ProcessID", _ProcessID);
|
||||
// Output Calculated Columns
|
||||
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp)
|
||||
{
|
||||
Direction = ParameterDirection.Output
|
||||
};
|
||||
cm.Parameters.Add(param_LastChanged);
|
||||
// CSLATODO: Define any additional output parameters
|
||||
cm.ExecuteNonQuery();
|
||||
// Save all values being returned from the Procedure
|
||||
_LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
MarkOld();
|
||||
// use the open connection to update child objects
|
||||
}
|
||||
@@ -814,14 +716,17 @@ namespace VEPROMS.CSLA.Library
|
||||
}
|
||||
internal void Update()
|
||||
{
|
||||
if (!this.IsDirty) return;
|
||||
if (!IsDirty) return;
|
||||
if (base.IsDirty)
|
||||
{
|
||||
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"];
|
||||
if (IsNew)
|
||||
_LastChanged = Session.Add(cn, ref _SessionID, _UserID, _DTSDtart, _DTSEnd, _DTSActivity, _MachineName, _ProcessID);
|
||||
else
|
||||
_LastChanged = Session.Update(cn, ref _SessionID, _UserID, _DTSDtart, _DTSEnd, _DTSActivity, ref _LastChanged, _MachineName, _ProcessID);
|
||||
using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"])
|
||||
{
|
||||
if (IsNew)
|
||||
_LastChanged = Session.Add(cn, ref _SessionID, _UserID, _DTSDtart, _DTSEnd, _DTSActivity, _MachineName, _ProcessID);
|
||||
else
|
||||
_LastChanged = Session.Update(cn, ref _SessionID, _UserID, _DTSDtart, _DTSEnd, _DTSActivity, ref _LastChanged, _MachineName, _ProcessID);
|
||||
}
|
||||
|
||||
MarkOld();
|
||||
}
|
||||
}
|
||||
@@ -846,8 +751,10 @@ namespace VEPROMS.CSLA.Library
|
||||
cm.Parameters.AddWithValue("@MachineName", machineName);
|
||||
cm.Parameters.AddWithValue("@ProcessID", processID);
|
||||
// Output Calculated Columns
|
||||
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp);
|
||||
param_LastChanged.Direction = ParameterDirection.Output;
|
||||
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp)
|
||||
{
|
||||
Direction = ParameterDirection.Output
|
||||
};
|
||||
cm.Parameters.Add(param_LastChanged);
|
||||
// CSLATODO: Define any additional output parameters
|
||||
cm.ExecuteNonQuery();
|
||||
@@ -932,16 +839,10 @@ namespace VEPROMS.CSLA.Library
|
||||
[Serializable()]
|
||||
private class ExistsCommand : CommandBase
|
||||
{
|
||||
private int _SessionID;
|
||||
private readonly int _SessionID;
|
||||
private bool _exists;
|
||||
public bool Exists
|
||||
{
|
||||
get { return _exists; }
|
||||
}
|
||||
public ExistsCommand(int sessionID)
|
||||
{
|
||||
_SessionID = sessionID;
|
||||
}
|
||||
public bool Exists => _exists;
|
||||
public ExistsCommand(int sessionID) => _SessionID = sessionID;
|
||||
protected override void DataPortal_Execute()
|
||||
{
|
||||
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Session.DataPortal_Execute", GetHashCode());
|
||||
@@ -957,7 +858,7 @@ namespace VEPROMS.CSLA.Library
|
||||
cm.CommandText = "existsSession";
|
||||
cm.Parameters.AddWithValue("@SessionID", _SessionID);
|
||||
int count = (int)cm.ExecuteScalar();
|
||||
_exists = (count > 0);
|
||||
_exists = count > 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -971,7 +872,7 @@ namespace VEPROMS.CSLA.Library
|
||||
#endregion
|
||||
// Standard Default Code
|
||||
#region extension
|
||||
SessionExtension _SessionExtension = new SessionExtension();
|
||||
readonly SessionExtension _SessionExtension = new SessionExtension();
|
||||
[Serializable()]
|
||||
partial class SessionExtension : extensionBase
|
||||
{
|
||||
@@ -980,18 +881,9 @@ namespace VEPROMS.CSLA.Library
|
||||
class extensionBase
|
||||
{
|
||||
// Default Values
|
||||
public virtual string DefaultUserID
|
||||
{
|
||||
get { return Environment.UserName.ToUpper(); }
|
||||
}
|
||||
public virtual DateTime DefaultDTSDtart
|
||||
{
|
||||
get { return DateTime.Now; }
|
||||
}
|
||||
public virtual DateTime DefaultDTSActivity
|
||||
{
|
||||
get { return DateTime.Now; }
|
||||
}
|
||||
public virtual string DefaultUserID => Environment.UserName.ToUpper();
|
||||
public virtual DateTime DefaultDTSDtart => DateTime.Now;
|
||||
public virtual DateTime DefaultDTSActivity => DateTime.Now;
|
||||
// Authorization Rules
|
||||
public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules)
|
||||
{
|
||||
@@ -1020,61 +912,13 @@ namespace VEPROMS.CSLA.Library
|
||||
{
|
||||
public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType)
|
||||
{
|
||||
if (destType == typeof(string) && value is Session)
|
||||
if (destType == typeof(string) && value is Session mysession)
|
||||
{
|
||||
// Return the ToString value
|
||||
return ((Session)value).ToString();
|
||||
return mysession.ToString();
|
||||
}
|
||||
return base.ConvertTo(context, culture, value, destType);
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
} // Namespace
|
||||
|
||||
|
||||
//// The following is a sample Extension File. You can use it to create SessionExt.cs
|
||||
//using System;
|
||||
//using System.Collections.Generic;
|
||||
//using System.Text;
|
||||
//using Csla;
|
||||
|
||||
//namespace VEPROMS.CSLA.Library
|
||||
//{
|
||||
// public partial class Session
|
||||
// {
|
||||
// partial class SessionExtension : extensionBase
|
||||
// {
|
||||
// // CSLATODO: Override automatic defaults
|
||||
// public virtual string DefaultUserID
|
||||
// {
|
||||
// get { return Environment.UserName.ToUpper(); }
|
||||
// }
|
||||
// public virtual DateTime DefaultDTSDtart
|
||||
// {
|
||||
// get { return DateTime.Now; }
|
||||
// }
|
||||
// public virtual DateTime DefaultDTSActivity
|
||||
// {
|
||||
// get { return DateTime.Now; }
|
||||
// }
|
||||
// public new void AddAuthorizationRules(Csla.Security.AuthorizationRules rules)
|
||||
// {
|
||||
// //rules.AllowRead(Dbid, "<Role(s)>");
|
||||
// }
|
||||
// public new void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules)
|
||||
// {
|
||||
// //rules.AllowInstanceRead(Dbid, "<Role(s)>");
|
||||
// }
|
||||
// public new void AddValidationRules(Csla.Validation.ValidationRules rules)
|
||||
// {
|
||||
// rules.AddRule(
|
||||
// Csla.Validation.CommonRules.StringMaxLength,
|
||||
// new Csla.Validation.CommonRules.MaxLengthRuleArgs("Name", 100));
|
||||
// }
|
||||
// public new void AddInstanceValidationRules(Csla.Validation.ValidationRules rules)
|
||||
// {
|
||||
// rules.AddInstanceRule(/* Instance Validation Rule */);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
|
||||
Reference in New Issue
Block a user