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;
|
||||
@@ -69,6 +67,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<User> _CacheList = new List<User>();
|
||||
protected static void AddToCache(User user)
|
||||
{
|
||||
@@ -78,6 +77,7 @@ namespace VEPROMS.CSLA.Library
|
||||
{
|
||||
while (_CacheList.Contains(user)) _CacheList.Remove(user); // In RemoveFromCache
|
||||
}
|
||||
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "Keeping Collections Not ReadOnly")]
|
||||
private static Dictionary<string, List<User>> _CacheByPrimaryKey = new Dictionary<string, List<User>>();
|
||||
private static void ConvertListToDictionary()
|
||||
{
|
||||
@@ -103,15 +103,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 _nextUID = -1;
|
||||
public static int NextUID
|
||||
{
|
||||
get { return _nextUID--; }
|
||||
}
|
||||
public static int NextUID => _nextUID--;
|
||||
private int _UID;
|
||||
[System.ComponentModel.DataObjectField(true, true)]
|
||||
public int UID
|
||||
@@ -400,10 +394,7 @@ namespace VEPROMS.CSLA.Library
|
||||
return _UserMemberships;
|
||||
}
|
||||
}
|
||||
public void Reset_UserMemberships()
|
||||
{
|
||||
_UserMembershipCount = -1;
|
||||
}
|
||||
public void Reset_UserMemberships() => _UserMembershipCount = -1;
|
||||
public override bool IsDirty
|
||||
{
|
||||
get
|
||||
@@ -418,37 +409,22 @@ namespace VEPROMS.CSLA.Library
|
||||
if (base.IsDirty || list.Contains(this))
|
||||
return base.IsDirty;
|
||||
list.Add(this);
|
||||
return base.IsDirty || (_UserMemberships == null ? false : _UserMemberships.IsDirtyList(list));
|
||||
}
|
||||
public override bool IsValid
|
||||
{
|
||||
get { return IsValidList(new List<object>()); }
|
||||
return base.IsDirty || (_UserMemberships != null && _UserMemberships.IsDirtyList(list));
|
||||
}
|
||||
public override bool IsValid => IsValidList(new List<object>());
|
||||
public bool IsValidList(List<object> list)
|
||||
{
|
||||
if (list.Contains(this))
|
||||
return (IsNew && !IsDirty) ? true : base.IsValid;
|
||||
return (IsNew && !IsDirty) || base.IsValid;
|
||||
list.Add(this);
|
||||
return ((IsNew && !IsDirty) ? true : base.IsValid) && (_UserMemberships == null ? true : _UserMemberships.IsValidList(list));
|
||||
return ((IsNew && !IsDirty) || base.IsValid) && (_UserMemberships == null || _UserMemberships.IsValidList(list));
|
||||
}
|
||||
// CSLATODO: Replace base User.ToString function as necessary
|
||||
/// <summary>
|
||||
/// Overrides Base ToString
|
||||
/// </summary>
|
||||
/// <returns>A string representation of current User</returns>
|
||||
//public override string ToString()
|
||||
//{
|
||||
// return base.ToString();
|
||||
//}
|
||||
// CSLATODO: Check User.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 User</returns>
|
||||
protected override object GetIdValue()
|
||||
{
|
||||
return MyUserUnique; // Absolutely Unique ID
|
||||
}
|
||||
protected override object GetIdValue() => MyUserUnique; // Absolutely Unique ID
|
||||
#endregion
|
||||
#region ValidationRules
|
||||
[NonSerialized]
|
||||
@@ -477,8 +453,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()
|
||||
@@ -532,49 +508,11 @@ namespace VEPROMS.CSLA.Library
|
||||
_UserExtension.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(UID, "<Role(s)>");
|
||||
//AuthorizationRules.AllowRead(UserID, "<Role(s)>");
|
||||
//AuthorizationRules.AllowRead(FirstName, "<Role(s)>");
|
||||
//AuthorizationRules.AllowRead(MiddleName, "<Role(s)>");
|
||||
//AuthorizationRules.AllowRead(LastName, "<Role(s)>");
|
||||
//AuthorizationRules.AllowRead(Suffix, "<Role(s)>");
|
||||
//AuthorizationRules.AllowRead(CourtesyTitle, "<Role(s)>");
|
||||
//AuthorizationRules.AllowRead(PhoneNumber, "<Role(s)>");
|
||||
//AuthorizationRules.AllowRead(CFGName, "<Role(s)>");
|
||||
//AuthorizationRules.AllowRead(UserLogin, "<Role(s)>");
|
||||
//AuthorizationRules.AllowRead(UserName, "<Role(s)>");
|
||||
//AuthorizationRules.AllowRead(Config, "<Role(s)>");
|
||||
//AuthorizationRules.AllowRead(DTS, "<Role(s)>");
|
||||
//AuthorizationRules.AllowRead(UsrID, "<Role(s)>");
|
||||
//AuthorizationRules.AllowWrite(UserID, "<Role(s)>");
|
||||
//AuthorizationRules.AllowWrite(FirstName, "<Role(s)>");
|
||||
//AuthorizationRules.AllowWrite(MiddleName, "<Role(s)>");
|
||||
//AuthorizationRules.AllowWrite(LastName, "<Role(s)>");
|
||||
//AuthorizationRules.AllowWrite(Suffix, "<Role(s)>");
|
||||
//AuthorizationRules.AllowWrite(CourtesyTitle, "<Role(s)>");
|
||||
//AuthorizationRules.AllowWrite(PhoneNumber, "<Role(s)>");
|
||||
//AuthorizationRules.AllowWrite(CFGName, "<Role(s)>");
|
||||
//AuthorizationRules.AllowWrite(UserLogin, "<Role(s)>");
|
||||
//AuthorizationRules.AllowWrite(UserName, "<Role(s)>");
|
||||
//AuthorizationRules.AllowWrite(Config, "<Role(s)>");
|
||||
//AuthorizationRules.AllowWrite(DTS, "<Role(s)>");
|
||||
//AuthorizationRules.AllowWrite(UsrID, "<Role(s)>");
|
||||
_UserExtension.AddAuthorizationRules(AuthorizationRules);
|
||||
}
|
||||
protected override void AddInstanceAuthorizationRules()
|
||||
@@ -582,55 +520,14 @@ namespace VEPROMS.CSLA.Library
|
||||
//CSLATODO: Who can read/write which fields
|
||||
_UserExtension.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;
|
||||
}
|
||||
/// <summary>
|
||||
/// determines if related records (Foreign Keys) will keep this Item from being deleted
|
||||
/// </summary>
|
||||
public bool CanDelete
|
||||
{
|
||||
get
|
||||
{
|
||||
// Check to make sure that there are not any related records
|
||||
int usedByCount = 0;
|
||||
usedByCount += _UserMembershipCount;
|
||||
return (usedByCount == 0);
|
||||
}
|
||||
}
|
||||
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 _UserUnique = 0;
|
||||
protected static int UserUnique
|
||||
{ get { return ++_UserUnique; } }
|
||||
private int _MyUserUnique = UserUnique;
|
||||
public int MyUserUnique // Absolutely Unique ID - Editable
|
||||
{ get { return _MyUserUnique; } }
|
||||
protected static int UserUnique => ++_UserUnique;
|
||||
private readonly int _MyUserUnique = UserUnique;
|
||||
// Absolutely Unique ID - Editable
|
||||
public int MyUserUnique => _MyUserUnique;
|
||||
protected User()
|
||||
{/* require use of factory methods */
|
||||
AddToCache(this);
|
||||
@@ -639,15 +536,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;
|
||||
~User()
|
||||
{
|
||||
_CountFinalized++;
|
||||
@@ -672,8 +565,6 @@ namespace VEPROMS.CSLA.Library
|
||||
}
|
||||
public static User New()
|
||||
{
|
||||
if (!CanAddObject())
|
||||
throw new System.Security.SecurityException("User not authorized to add a User");
|
||||
try
|
||||
{
|
||||
return DataPortal.Create<User>();
|
||||
@@ -750,8 +641,6 @@ namespace VEPROMS.CSLA.Library
|
||||
}
|
||||
public static User Get(int uid)
|
||||
{
|
||||
if (!CanGetObject())
|
||||
throw new System.Security.SecurityException("User not authorized to view a User");
|
||||
try
|
||||
{
|
||||
User tmp = GetCachedByPrimaryKey(uid);
|
||||
@@ -772,19 +661,10 @@ namespace VEPROMS.CSLA.Library
|
||||
throw new DbCslaException("Error on User.Get", ex);
|
||||
}
|
||||
}
|
||||
public static User Get(SafeDataReader dr)
|
||||
{
|
||||
if (dr.Read()) return new User(dr);
|
||||
return null;
|
||||
}
|
||||
internal User(SafeDataReader dr)
|
||||
{
|
||||
ReadData(dr);
|
||||
}
|
||||
public static User Get(SafeDataReader dr) => dr.Read() ? new User(dr) : null;
|
||||
internal User(SafeDataReader dr) => ReadData(dr);
|
||||
public static void Delete(int uid)
|
||||
{
|
||||
if (!CanDeleteObject())
|
||||
throw new System.Security.SecurityException("User not authorized to remove a User");
|
||||
try
|
||||
{
|
||||
DataPortal.Delete(new PKCriteria(uid));
|
||||
@@ -796,12 +676,6 @@ namespace VEPROMS.CSLA.Library
|
||||
}
|
||||
public override User Save()
|
||||
{
|
||||
if (IsDeleted && !CanDeleteObject())
|
||||
throw new System.Security.SecurityException("User not authorized to remove a User");
|
||||
else if (IsNew && !CanAddObject())
|
||||
throw new System.Security.SecurityException("User not authorized to add a User");
|
||||
else if (!CanEditObject())
|
||||
throw new System.Security.SecurityException("User not authorized to update a User");
|
||||
try
|
||||
{
|
||||
BuildRefreshList();
|
||||
@@ -821,13 +695,9 @@ namespace VEPROMS.CSLA.Library
|
||||
[Serializable()]
|
||||
protected class PKCriteria
|
||||
{
|
||||
private int _UID;
|
||||
public int UID
|
||||
{ get { return _UID; } }
|
||||
public PKCriteria(int uid)
|
||||
{
|
||||
_UID = uid;
|
||||
}
|
||||
private readonly int _UID;
|
||||
public int UID => _UID;
|
||||
public PKCriteria(int uid) => _UID = uid;
|
||||
}
|
||||
// CSLATODO: If Create needs to access DB - It should not be marked RunLocal
|
||||
[RunLocal()]
|
||||
@@ -938,45 +808,52 @@ 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 = "addUser";
|
||||
// Input All Fields - Except Calculated Columns
|
||||
cm.Parameters.AddWithValue("@UserID", _UserID);
|
||||
cm.Parameters.AddWithValue("@FirstName", _FirstName);
|
||||
cm.Parameters.AddWithValue("@MiddleName", _MiddleName);
|
||||
cm.Parameters.AddWithValue("@LastName", _LastName);
|
||||
cm.Parameters.AddWithValue("@Suffix", _Suffix);
|
||||
cm.Parameters.AddWithValue("@CourtesyTitle", _CourtesyTitle);
|
||||
cm.Parameters.AddWithValue("@PhoneNumber", _PhoneNumber);
|
||||
cm.Parameters.AddWithValue("@CFGName", _CFGName);
|
||||
cm.Parameters.AddWithValue("@UserLogin", _UserLogin);
|
||||
cm.Parameters.AddWithValue("@UserName", _UserName);
|
||||
cm.Parameters.AddWithValue("@Config", _Config);
|
||||
if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS);
|
||||
cm.Parameters.AddWithValue("@UsrID", _UsrID);
|
||||
// Output Calculated Columns
|
||||
SqlParameter param_UID = new SqlParameter("@newUID", SqlDbType.Int);
|
||||
param_UID.Direction = ParameterDirection.Output;
|
||||
cm.Parameters.Add(param_UID);
|
||||
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
|
||||
_UID = (int)cm.Parameters["@newUID"].Value;
|
||||
_LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value;
|
||||
using (SqlCommand cm = cn.CreateCommand())
|
||||
{
|
||||
cm.CommandType = CommandType.StoredProcedure;
|
||||
cm.CommandTimeout = Database.SQLTimeout;
|
||||
cm.CommandText = "addUser";
|
||||
// Input All Fields - Except Calculated Columns
|
||||
cm.Parameters.AddWithValue("@UserID", _UserID);
|
||||
cm.Parameters.AddWithValue("@FirstName", _FirstName);
|
||||
cm.Parameters.AddWithValue("@MiddleName", _MiddleName);
|
||||
cm.Parameters.AddWithValue("@LastName", _LastName);
|
||||
cm.Parameters.AddWithValue("@Suffix", _Suffix);
|
||||
cm.Parameters.AddWithValue("@CourtesyTitle", _CourtesyTitle);
|
||||
cm.Parameters.AddWithValue("@PhoneNumber", _PhoneNumber);
|
||||
cm.Parameters.AddWithValue("@CFGName", _CFGName);
|
||||
cm.Parameters.AddWithValue("@UserLogin", _UserLogin);
|
||||
cm.Parameters.AddWithValue("@UserName", _UserName);
|
||||
cm.Parameters.AddWithValue("@Config", _Config);
|
||||
if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS);
|
||||
cm.Parameters.AddWithValue("@UsrID", _UsrID);
|
||||
// Output Calculated Columns
|
||||
SqlParameter param_UID = new SqlParameter("@newUID", SqlDbType.Int)
|
||||
{
|
||||
Direction = ParameterDirection.Output
|
||||
};
|
||||
cm.Parameters.Add(param_UID);
|
||||
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
|
||||
_UID = (int)cm.Parameters["@newUID"].Value;
|
||||
_LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value;
|
||||
}
|
||||
}
|
||||
|
||||
MarkOld();
|
||||
// update child objects
|
||||
if (_UserMemberships != null) _UserMemberships.Update(this);
|
||||
_UserMemberships?.Update(this);
|
||||
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] User.SQLInsert", GetHashCode());
|
||||
}
|
||||
catch (Exception ex)
|
||||
@@ -1012,11 +889,15 @@ namespace VEPROMS.CSLA.Library
|
||||
if (dts.Year >= 1753 && dts.Year <= 9999) cm.Parameters.AddWithValue("@DTS", dts);
|
||||
cm.Parameters.AddWithValue("@UsrID", usrID);
|
||||
// Output Calculated Columns
|
||||
SqlParameter param_UID = new SqlParameter("@newUID", SqlDbType.Int);
|
||||
param_UID.Direction = ParameterDirection.Output;
|
||||
SqlParameter param_UID = new SqlParameter("@newUID", SqlDbType.Int)
|
||||
{
|
||||
Direction = ParameterDirection.Output
|
||||
};
|
||||
cm.Parameters.Add(param_UID);
|
||||
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();
|
||||
@@ -1061,43 +942,48 @@ namespace VEPROMS.CSLA.Library
|
||||
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] User.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 = "updateUser";
|
||||
// All Fields including Calculated Fields
|
||||
cm.Parameters.AddWithValue("@UID", _UID);
|
||||
cm.Parameters.AddWithValue("@UserID", _UserID);
|
||||
cm.Parameters.AddWithValue("@FirstName", _FirstName);
|
||||
cm.Parameters.AddWithValue("@MiddleName", _MiddleName);
|
||||
cm.Parameters.AddWithValue("@LastName", _LastName);
|
||||
cm.Parameters.AddWithValue("@Suffix", _Suffix);
|
||||
cm.Parameters.AddWithValue("@CourtesyTitle", _CourtesyTitle);
|
||||
cm.Parameters.AddWithValue("@PhoneNumber", _PhoneNumber);
|
||||
cm.Parameters.AddWithValue("@CFGName", _CFGName);
|
||||
cm.Parameters.AddWithValue("@UserLogin", _UserLogin);
|
||||
cm.Parameters.AddWithValue("@UserName", _UserName);
|
||||
cm.Parameters.AddWithValue("@Config", _Config);
|
||||
if (_DTS.Year >= 1753 && _DTS.Year <= 9999) 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);
|
||||
// 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 = "updateUser";
|
||||
// All Fields including Calculated Fields
|
||||
cm.Parameters.AddWithValue("@UID", _UID);
|
||||
cm.Parameters.AddWithValue("@UserID", _UserID);
|
||||
cm.Parameters.AddWithValue("@FirstName", _FirstName);
|
||||
cm.Parameters.AddWithValue("@MiddleName", _MiddleName);
|
||||
cm.Parameters.AddWithValue("@LastName", _LastName);
|
||||
cm.Parameters.AddWithValue("@Suffix", _Suffix);
|
||||
cm.Parameters.AddWithValue("@CourtesyTitle", _CourtesyTitle);
|
||||
cm.Parameters.AddWithValue("@PhoneNumber", _PhoneNumber);
|
||||
cm.Parameters.AddWithValue("@CFGName", _CFGName);
|
||||
cm.Parameters.AddWithValue("@UserLogin", _UserLogin);
|
||||
cm.Parameters.AddWithValue("@UserName", _UserName);
|
||||
cm.Parameters.AddWithValue("@Config", _Config);
|
||||
if (_DTS.Year >= 1753 && _DTS.Year <= 9999) 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)
|
||||
{
|
||||
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
|
||||
if (_UserMemberships != null) _UserMemberships.Update(this);
|
||||
_UserMemberships?.Update(this);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -1108,17 +994,20 @@ 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 = User.Add(cn, ref _UID, _UserID, _FirstName, _MiddleName, _LastName, _Suffix, _CourtesyTitle, _PhoneNumber, _CFGName, _UserLogin, _UserName, _Config, _DTS, _UsrID);
|
||||
else
|
||||
_LastChanged = User.Update(cn, ref _UID, _UserID, _FirstName, _MiddleName, _LastName, _Suffix, _CourtesyTitle, _PhoneNumber, _CFGName, _UserLogin, _UserName, _Config, _DTS, _UsrID, ref _LastChanged);
|
||||
using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"])
|
||||
{
|
||||
if (IsNew)
|
||||
_LastChanged = User.Add(cn, ref _UID, _UserID, _FirstName, _MiddleName, _LastName, _Suffix, _CourtesyTitle, _PhoneNumber, _CFGName, _UserLogin, _UserName, _Config, _DTS, _UsrID);
|
||||
else
|
||||
_LastChanged = User.Update(cn, ref _UID, _UserID, _FirstName, _MiddleName, _LastName, _Suffix, _CourtesyTitle, _PhoneNumber, _CFGName, _UserLogin, _UserName, _Config, _DTS, _UsrID, ref _LastChanged);
|
||||
}
|
||||
|
||||
MarkOld();
|
||||
}
|
||||
if (_UserMemberships != null) _UserMemberships.Update(this);
|
||||
_UserMemberships?.Update(this);
|
||||
}
|
||||
[Transactional(TransactionalTypes.TransactionScope)]
|
||||
public static byte[] Update(SqlConnection cn, ref int uid, string userID, string firstName, string middleName, string lastName, string suffix, string courtesyTitle, string phoneNumber, string cFGName, string userLogin, string userName, string config, DateTime dts, string usrID, ref byte[] lastChanged)
|
||||
@@ -1148,8 +1037,10 @@ namespace VEPROMS.CSLA.Library
|
||||
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;
|
||||
SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp)
|
||||
{
|
||||
Direction = ParameterDirection.Output
|
||||
};
|
||||
cm.Parameters.Add(param_LastChanged);
|
||||
// CSLATODO: Define any additional output parameters
|
||||
cm.ExecuteNonQuery();
|
||||
@@ -1234,16 +1125,10 @@ namespace VEPROMS.CSLA.Library
|
||||
[Serializable()]
|
||||
private class ExistsCommand : CommandBase
|
||||
{
|
||||
private int _UID;
|
||||
private readonly int _UID;
|
||||
private bool _exists;
|
||||
public bool Exists
|
||||
{
|
||||
get { return _exists; }
|
||||
}
|
||||
public ExistsCommand(int uid)
|
||||
{
|
||||
_UID = uid;
|
||||
}
|
||||
public bool Exists => _exists;
|
||||
public ExistsCommand(int uid) => _UID = uid;
|
||||
protected override void DataPortal_Execute()
|
||||
{
|
||||
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] User.DataPortal_Execute", GetHashCode());
|
||||
@@ -1259,7 +1144,7 @@ namespace VEPROMS.CSLA.Library
|
||||
cm.CommandText = "existsUser";
|
||||
cm.Parameters.AddWithValue("@UID", _UID);
|
||||
int count = (int)cm.ExecuteScalar();
|
||||
_exists = (count > 0);
|
||||
_exists = count > 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1273,7 +1158,7 @@ namespace VEPROMS.CSLA.Library
|
||||
#endregion
|
||||
// Standard Default Code
|
||||
#region extension
|
||||
UserExtension _UserExtension = new UserExtension();
|
||||
readonly UserExtension _UserExtension = new UserExtension();
|
||||
[Serializable()]
|
||||
partial class UserExtension : extensionBase
|
||||
{
|
||||
@@ -1282,18 +1167,9 @@ namespace VEPROMS.CSLA.Library
|
||||
class extensionBase
|
||||
{
|
||||
// Default Values
|
||||
public virtual string DefaultUserID
|
||||
{
|
||||
get { return Environment.UserName.ToUpper(); }
|
||||
}
|
||||
public virtual DateTime DefaultDTS
|
||||
{
|
||||
get { return DateTime.Now; }
|
||||
}
|
||||
public virtual string DefaultUsrID
|
||||
{
|
||||
get { return Volian.Base.Library.VlnSettings.UserID; }
|
||||
}
|
||||
public virtual string DefaultUserID => Environment.UserName.ToUpper();
|
||||
public virtual DateTime DefaultDTS => DateTime.Now;
|
||||
public virtual string DefaultUsrID => Volian.Base.Library.VlnSettings.UserID;
|
||||
// Authorization Rules
|
||||
public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules)
|
||||
{
|
||||
@@ -1322,61 +1198,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 User)
|
||||
if (destType == typeof(string) && value is User myuser)
|
||||
{
|
||||
// Return the ToString value
|
||||
return ((User)value).ToString();
|
||||
return myuser.ToString();
|
||||
}
|
||||
return base.ConvertTo(context, culture, value, destType);
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
} // Namespace
|
||||
|
||||
|
||||
//// The following is a sample Extension File. You can use it to create UserExt.cs
|
||||
//using System;
|
||||
//using System.Collections.Generic;
|
||||
//using System.Text;
|
||||
//using Csla;
|
||||
|
||||
//namespace VEPROMS.CSLA.Library
|
||||
//{
|
||||
// public partial class User
|
||||
// {
|
||||
// partial class UserExtension : extensionBase
|
||||
// {
|
||||
// // CSLATODO: Override automatic defaults
|
||||
// public virtual string DefaultUserID
|
||||
// {
|
||||
// get { return Environment.UserName.ToUpper(); }
|
||||
// }
|
||||
// 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 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