CSLA - Generated - C Items

This commit is contained in:
2026-09-04 13:34:46 -04:00
parent 222371302f
commit 8a55eb57d6
27 changed files with 1563 additions and 3464 deletions
+149 -335
View File
@@ -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;
@@ -122,6 +120,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<Content> _CacheList = new List<Content>();
protected static void AddToCache(Content content)
{
@@ -131,6 +130,7 @@ namespace VEPROMS.CSLA.Library
{
while (_CacheList.Contains(content)) _CacheList.Remove(content); // In RemoveFromCache
}
[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0044:Add readonly modifier", Justification = "Keeping Collections Not ReadOnly")]
private static Dictionary<string, List<Content>> _CacheByPrimaryKey = new Dictionary<string, List<Content>>();
private static void ConvertListToDictionary()
{
@@ -159,15 +159,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 _nextContentID = -1;
public static int NextContentID
{
get { return _nextContentID--; }
}
public static int NextContentID => _nextContentID--;
private int _ContentID;
[System.ComponentModel.DataObjectField(true, true)]
public int ContentID
@@ -369,10 +363,7 @@ namespace VEPROMS.CSLA.Library
return _ContentDetails;
}
}
public void Reset_ContentDetails()
{
_ContentDetailCount = -1;
}
public void Reset_ContentDetails() => _ContentDetailCount = -1;
private int _ContentEntryCount = 0;
/// <summary>
/// Count of ContentEntries for this Content
@@ -564,10 +555,7 @@ namespace VEPROMS.CSLA.Library
return _ContentRoUsages;
}
}
public void Reset_ContentRoUsages()
{
_ContentRoUsageCount = -1;
}
public void Reset_ContentRoUsages() => _ContentRoUsageCount = -1;
private int _ContentTransitionCount = 0;
/// <summary>
/// Count of ContentTransitions for this Content
@@ -601,10 +589,7 @@ namespace VEPROMS.CSLA.Library
return _ContentTransitions;
}
}
public void Reset_ContentTransitions()
{
_ContentTransitionCount = -1;
}
public void Reset_ContentTransitions() => _ContentTransitionCount = -1;
private int _ContentZContentCount = 0;
/// <summary>
/// Count of ContentZContents for this Content
@@ -645,37 +630,21 @@ namespace VEPROMS.CSLA.Library
if (base.IsDirty || list.Contains(this))
return base.IsDirty;
list.Add(this);
return base.IsDirty || (_ContentDetails == null ? false : _ContentDetails.IsDirtyList(list)) || (_MyEntry == null ? false : _MyEntry.IsDirtyList(list)) || (_MyGrid == null ? false : _MyGrid.IsDirtyList(list)) || (_MyImage == null ? false : _MyImage.IsDirtyList(list)) || (_ContentItems == null ? false : _ContentItems.IsDirtyList(list)) || (_ContentParts == null ? false : _ContentParts.IsDirtyList(list)) || (_ContentRoUsages == null ? false : _ContentRoUsages.IsDirtyList(list)) || (_ContentTransitions == null ? false : _ContentTransitions.IsDirtyList(list)) || (_MyZContent == null ? false : _MyZContent.IsDirtyList(list)) || (_MyFormat == null ? false : _MyFormat.IsDirtyList(list));
}
public override bool IsValid
{
get { return IsValidList(new List<object>()); }
return base.IsDirty || (_ContentDetails != null && _ContentDetails.IsDirtyList(list)) || (_MyEntry != null && _MyEntry.IsDirtyList(list)) || (_MyGrid != null && _MyGrid.IsDirtyList(list)) || (_MyImage != null && _MyImage.IsDirtyList(list)) || (_ContentItems != null && _ContentItems.IsDirtyList(list)) || (_ContentParts != null && _ContentParts.IsDirtyList(list)) || (_ContentRoUsages != null && _ContentRoUsages.IsDirtyList(list)) || (_ContentTransitions != null && _ContentTransitions.IsDirtyList(list)) || (_MyZContent != null && _MyZContent.IsDirtyList(list)) || (_MyFormat != null && _MyFormat.IsDirtyList(list));
}
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) && (_ContentDetails == null ? true : _ContentDetails.IsValidList(list)) && (_MyEntry == null ? true : _MyEntry.IsValidList(list)) && (_MyGrid == null ? true : _MyGrid.IsValidList(list)) && (_MyImage == null ? true : _MyImage.IsValidList(list)) && (_ContentItems == null ? true : _ContentItems.IsValidList(list)) && (_ContentParts == null ? true : _ContentParts.IsValidList(list)) && (_ContentRoUsages == null ? true : _ContentRoUsages.IsValidList(list)) && (_ContentTransitions == null ? true : _ContentTransitions.IsValidList(list)) && (_MyZContent == null ? true : _MyZContent.IsValidList(list)) && (_MyFormat == null ? true : _MyFormat.IsValidList(list));
return ((IsNew && !IsDirty) || base.IsValid) && (_ContentDetails == null || _ContentDetails.IsValidList(list)) && (_MyEntry == null || _MyEntry.IsValidList(list)) && (_MyGrid == null || _MyGrid.IsValidList(list)) && (_MyImage == null || _MyImage.IsValidList(list)) && (_ContentItems == null || _ContentItems.IsValidList(list)) && (_ContentParts == null || _ContentParts.IsValidList(list)) && (_ContentRoUsages == null || _ContentRoUsages.IsValidList(list)) && (_ContentTransitions == null || _ContentTransitions.IsValidList(list)) && (_MyZContent == null || _MyZContent.IsValidList(list)) && (_MyFormat == null || _MyFormat.IsValidList(list));
}
// CSLATODO: Replace base Content.ToString function as necessary
/// <summary>
/// Overrides Base ToString
/// </summary>
/// <returns>A string representation of current Content</returns>
//public override string ToString()
//{
// return base.ToString();
//}
// CSLATODO: Check Content.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 Content</returns>
protected override object GetIdValue()
{
return MyContentUnique; // Absolutely Unique ID
}
protected override object GetIdValue() => MyContentUnique; // Absolutely Unique ID
#endregion
#region ValidationRules
[NonSerialized]
@@ -713,8 +682,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()
@@ -742,37 +711,11 @@ namespace VEPROMS.CSLA.Library
_ContentExtension.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(ContentID, "<Role(s)>");
//AuthorizationRules.AllowRead(Number, "<Role(s)>");
//AuthorizationRules.AllowRead(Text, "<Role(s)>");
//AuthorizationRules.AllowRead(Type, "<Role(s)>");
//AuthorizationRules.AllowRead(FormatID, "<Role(s)>");
//AuthorizationRules.AllowRead(Config, "<Role(s)>");
//AuthorizationRules.AllowRead(DTS, "<Role(s)>");
//AuthorizationRules.AllowRead(UserID, "<Role(s)>");
//AuthorizationRules.AllowWrite(Number, "<Role(s)>");
//AuthorizationRules.AllowWrite(Text, "<Role(s)>");
//AuthorizationRules.AllowWrite(Type, "<Role(s)>");
//AuthorizationRules.AllowWrite(FormatID, "<Role(s)>");
//AuthorizationRules.AllowWrite(Config, "<Role(s)>");
//AuthorizationRules.AllowWrite(DTS, "<Role(s)>");
//AuthorizationRules.AllowWrite(UserID, "<Role(s)>");
_ContentExtension.AddAuthorizationRules(AuthorizationRules);
}
protected override void AddInstanceAuthorizationRules()
@@ -780,63 +723,14 @@ namespace VEPROMS.CSLA.Library
//CSLATODO: Who can read/write which fields
_ContentExtension.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 += _ContentDetailCount;
usedByCount += _ContentEntryCount;
usedByCount += _ContentGridCount;
usedByCount += _ContentImageCount;
usedByCount += _ContentItemCount;
usedByCount += _ContentPartCount;
usedByCount += _ContentRoUsageCount;
usedByCount += _ContentTransitionCount;
usedByCount += _ContentZContentCount;
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 _ContentUnique = 0;
protected static int ContentUnique
{ get { return ++_ContentUnique; } }
private int _MyContentUnique = ContentUnique;
public int MyContentUnique // Absolutely Unique ID - Editable
{ get { return _MyContentUnique; } }
protected static int ContentUnique => ++_ContentUnique;
private readonly int _MyContentUnique = ContentUnique;
// Absolutely Unique ID - Editable
public int MyContentUnique => _MyContentUnique;
protected Content()
{/* require use of factory methods */
AddToCache(this);
@@ -850,15 +744,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;
~Content()
{
_CountFinalized++;
@@ -891,26 +781,6 @@ namespace VEPROMS.CSLA.Library
_MyGrid = null;
}
_Text = null;
//if (_ContentDetails != null)
// _ContentDetails = null;
//if (_ContentItems != null)
//{
// _ContentItems = null;
// //foreach (ContentItem ci in _ContentItems)
// // ci.Dispose();
//}
//if (_ContentRoUsages != null)
//{
// //foreach (ContentRoUsage cr in _ContentRoUsages)
// // cr.Dispose();
// _ContentRoUsages = null;
//}
//if (_ContentTransitions != null)
//{
// foreach (ContentTransition ct in _ContentTransitions)
// ct.Dispose();
// _ContentTransitions = null;
//}
}
private void RemoveFromDictionaries()
{
@@ -925,8 +795,6 @@ namespace VEPROMS.CSLA.Library
}
public static Content New()
{
if (!CanAddObject())
throw new System.Security.SecurityException("User not authorized to add a Content");
try
{
return DataPortal.Create<Content>();
@@ -992,8 +860,6 @@ namespace VEPROMS.CSLA.Library
}
public static Content Get(int contentID, bool forcerefresh = false)
{
if (!CanGetObject())
throw new System.Security.SecurityException("User not authorized to view a Content");
try
{
//C2019-036 View Only mode work with Checked Out Procedures
@@ -1028,14 +894,9 @@ namespace VEPROMS.CSLA.Library
if (dr.Read()) return new Content(dr);
return null;
}
internal Content(SafeDataReader dr)
{
ReadData(dr);
}
internal Content(SafeDataReader dr) => ReadData(dr);
public static void Delete(int contentID)
{
if (!CanDeleteObject())
throw new System.Security.SecurityException("User not authorized to remove a Content");
try
{
DataPortal.Delete(new PKCriteria(contentID));
@@ -1047,12 +908,6 @@ namespace VEPROMS.CSLA.Library
}
public override Content Save()
{
if (IsDeleted && !CanDeleteObject())
throw new System.Security.SecurityException("User not authorized to remove a Content");
else if (IsNew && !CanAddObject())
throw new System.Security.SecurityException("User not authorized to add a Content");
else if (!CanEditObject())
throw new System.Security.SecurityException("User not authorized to update a Content");
try
{
BuildRefreshList();
@@ -1072,13 +927,9 @@ namespace VEPROMS.CSLA.Library
[Serializable()]
protected class PKCriteria
{
private int _ContentID;
public int ContentID
{ get { return _ContentID; } }
public PKCriteria(int contentID)
{
_ContentID = contentID;
}
private readonly int _ContentID;
public int ContentID => _ContentID;
public PKCriteria(int contentID) => _ContentID = contentID;
}
// CSLATODO: If Create needs to access DB - It should not be marked RunLocal
[RunLocal()]
@@ -1214,48 +1065,55 @@ namespace VEPROMS.CSLA.Library
[Transactional(TransactionalTypes.TransactionScope)]
internal void SQLInsert()
{
if (!this.IsDirty) return;
if (!IsDirty) return;
try
{
if (_MyFormat != null) _MyFormat.Update();
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"];
using (SqlCommand cm = cn.CreateCommand())
_MyFormat?.Update();
using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"])
{
cm.CommandType = CommandType.StoredProcedure;
cm.CommandTimeout = Database.SQLTimeout;
cm.CommandText = "addContent";
// Input All Fields - Except Calculated Columns
cm.Parameters.AddWithValue("@Number", _Number);
cm.Parameters.AddWithValue("@Text", _Text);
cm.Parameters.AddWithValue("@Type", _Type);
cm.Parameters.AddWithValue("@FormatID", FormatID);
cm.Parameters.AddWithValue("@Config", _Config);
if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS);
cm.Parameters.AddWithValue("@UserID", _UserID);
// Output Calculated Columns
SqlParameter param_ContentID = new SqlParameter("@newContentID", SqlDbType.Int);
param_ContentID.Direction = ParameterDirection.Output;
cm.Parameters.Add(param_ContentID);
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
_ContentID = (int)cm.Parameters["@newContentID"].Value;
_LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value;
using (SqlCommand cm = cn.CreateCommand())
{
cm.CommandType = CommandType.StoredProcedure;
cm.CommandTimeout = Database.SQLTimeout;
cm.CommandText = "addContent";
// Input All Fields - Except Calculated Columns
cm.Parameters.AddWithValue("@Number", _Number);
cm.Parameters.AddWithValue("@Text", _Text);
cm.Parameters.AddWithValue("@Type", _Type);
cm.Parameters.AddWithValue("@FormatID", FormatID);
cm.Parameters.AddWithValue("@Config", _Config);
if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS);
cm.Parameters.AddWithValue("@UserID", _UserID);
// Output Calculated Columns
SqlParameter param_ContentID = new SqlParameter("@newContentID", SqlDbType.Int)
{
Direction = ParameterDirection.Output
};
cm.Parameters.Add(param_ContentID);
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
_ContentID = (int)cm.Parameters["@newContentID"].Value;
_LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value;
}
}
MarkOld();
// update child objects
if (_ContentItems != null) _ContentItems.Update(this);
if (_ContentDetails != null) _ContentDetails.Update(this);
if (_MyEntry != null) _MyEntry.Update(this);
if (_MyGrid != null) _MyGrid.Update(this);
if (_MyImage != null) _MyImage.Update(this);
if (_ContentParts != null) _ContentParts.Update(this);
if (_ContentRoUsages != null) _ContentRoUsages.Update(this);
if (_ContentTransitions != null) _ContentTransitions.Update(this);
if (_MyZContent != null) _MyZContent.Update(this);
_ContentItems?.Update(this);
_ContentDetails?.Update(this);
_MyEntry?.Update(this);
_MyGrid?.Update(this);
_MyImage?.Update(this);
_ContentParts?.Update(this);
_ContentRoUsages?.Update(this);
_ContentTransitions?.Update(this);
_MyZContent?.Update(this);
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Content.SQLInsert", GetHashCode());
}
catch (Exception ex)
@@ -1285,11 +1143,15 @@ namespace VEPROMS.CSLA.Library
if (dts.Year >= 1753 && dts.Year <= 9999) cm.Parameters.AddWithValue("@DTS", dts);
cm.Parameters.AddWithValue("@UserID", userID);
// Output Calculated Columns
SqlParameter param_ContentID = new SqlParameter("@newContentID", SqlDbType.Int);
param_ContentID.Direction = ParameterDirection.Output;
SqlParameter param_ContentID = new SqlParameter("@newContentID", SqlDbType.Int)
{
Direction = ParameterDirection.Output
};
cm.Parameters.Add(param_ContentID);
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();
@@ -1334,47 +1196,52 @@ namespace VEPROMS.CSLA.Library
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Content.SQLUpdate", GetHashCode());
try
{
if (_MyFormat != null) _MyFormat.Update();
SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"];
if (base.IsDirty)
_MyFormat?.Update();
using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"])
{
using (SqlCommand cm = cn.CreateCommand())
if (base.IsDirty)
{
cm.CommandType = CommandType.StoredProcedure;
cm.CommandTimeout = Database.SQLTimeout;
//Volian.Base.Library.vlnStackTrace.ShowStackLocal("ContentID={0}", _ContentID.ToString());
cm.CommandText = "updateContent";
// All Fields including Calculated Fields
cm.Parameters.AddWithValue("@ContentID", _ContentID);
cm.Parameters.AddWithValue("@Number", _Number);
cm.Parameters.AddWithValue("@Text", _Text);
cm.Parameters.AddWithValue("@Type", _Type);
cm.Parameters.AddWithValue("@FormatID", FormatID);
cm.Parameters.AddWithValue("@Config", _Config);
if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS);
cm.Parameters.AddWithValue("@UserID", _UserID);
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;
//Volian.Base.Library.vlnStackTrace.ShowStackLocal("ContentID={0}", _ContentID.ToString());
cm.CommandText = "updateContent";
// All Fields including Calculated Fields
cm.Parameters.AddWithValue("@ContentID", _ContentID);
cm.Parameters.AddWithValue("@Number", _Number);
cm.Parameters.AddWithValue("@Text", _Text);
cm.Parameters.AddWithValue("@Type", _Type);
cm.Parameters.AddWithValue("@FormatID", FormatID);
cm.Parameters.AddWithValue("@Config", _Config);
if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS);
cm.Parameters.AddWithValue("@UserID", _UserID);
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 (_ContentItems != null) _ContentItems.Update(this);
if (_ContentDetails != null) _ContentDetails.Update(this);
if (_MyEntry != null) _MyEntry.Update(this);
if (_MyGrid != null) _MyGrid.Update(this);
if (_MyImage != null) _MyImage.Update(this);
if (_ContentParts != null) _ContentParts.Update(this);
if (_ContentRoUsages != null) _ContentRoUsages.Update(this);
if (_ContentTransitions != null) _ContentTransitions.Update(this);
if (_MyZContent != null) _MyZContent.Update(this);
_ContentItems?.Update(this);
_ContentDetails?.Update(this);
_MyEntry?.Update(this);
_MyGrid?.Update(this);
_MyImage?.Update(this);
_ContentParts?.Update(this);
_ContentRoUsages?.Update(this);
_ContentTransitions?.Update(this);
_MyZContent?.Update(this);
}
catch (Exception ex)
{
@@ -1385,25 +1252,28 @@ 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 = Content.Add(cn, ref _ContentID, _Number, _Text, _Type, _MyFormat, _Config, _DTS, _UserID);
else
_LastChanged = Content.Update(cn, ref _ContentID, _Number, _Text, _Type, _FormatID, _Config, _DTS, _UserID, ref _LastChanged);
using (SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"])
{
if (IsNew)
_LastChanged = Content.Add(cn, ref _ContentID, _Number, _Text, _Type, _MyFormat, _Config, _DTS, _UserID);
else
_LastChanged = Content.Update(cn, ref _ContentID, _Number, _Text, _Type, _FormatID, _Config, _DTS, _UserID, ref _LastChanged);
}
MarkOld();
}
if (_ContentItems != null) _ContentItems.Update(this);
if (_ContentDetails != null) _ContentDetails.Update(this);
if (_MyEntry != null) _MyEntry.Update(this);
if (_MyGrid != null) _MyGrid.Update(this);
if (_MyImage != null) _MyImage.Update(this);
if (_ContentParts != null) _ContentParts.Update(this);
if (_ContentRoUsages != null) _ContentRoUsages.Update(this);
if (_ContentTransitions != null) _ContentTransitions.Update(this);
if (_MyZContent != null) _MyZContent.Update(this);
_ContentItems?.Update(this);
_ContentDetails?.Update(this);
_MyEntry?.Update(this);
_MyGrid?.Update(this);
_MyImage?.Update(this);
_ContentParts?.Update(this);
_ContentRoUsages?.Update(this);
_ContentTransitions?.Update(this);
_MyZContent?.Update(this);
}
[Transactional(TransactionalTypes.TransactionScope)]
public static byte[] Update(SqlConnection cn, ref int contentID, string number, string text, int? type, int? formatID, string config, DateTime dts, string userID, ref byte[] lastChanged)
@@ -1427,8 +1297,10 @@ namespace VEPROMS.CSLA.Library
cm.Parameters.AddWithValue("@UserID", userID);
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();
@@ -1443,10 +1315,7 @@ namespace VEPROMS.CSLA.Library
}
}
[Transactional(TransactionalTypes.TransactionScope)]
protected override void DataPortal_DeleteSelf()
{
DataPortal_Delete(new PKCriteria(_ContentID));
}
protected override void DataPortal_DeleteSelf() => DataPortal_Delete(new PKCriteria(_ContentID));
[Transactional(TransactionalTypes.TransactionScope)]
private void DataPortal_Delete(PKCriteria criteria)
{
@@ -1513,16 +1382,10 @@ namespace VEPROMS.CSLA.Library
[Serializable()]
private class ExistsCommand : CommandBase
{
private int _ContentID;
private readonly int _ContentID;
private bool _exists;
public bool Exists
{
get { return _exists; }
}
public ExistsCommand(int contentID)
{
_ContentID = contentID;
}
public bool Exists => _exists;
public ExistsCommand(int contentID) => _ContentID = contentID;
protected override void DataPortal_Execute()
{
if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Content.DataPortal_Execute", GetHashCode());
@@ -1552,7 +1415,7 @@ namespace VEPROMS.CSLA.Library
#endregion
// Standard Default Code
#region extension
ContentExtension _ContentExtension = new ContentExtension();
readonly ContentExtension _ContentExtension = new ContentExtension();
[Serializable()]
partial class ContentExtension : extensionBase
{
@@ -1561,14 +1424,8 @@ namespace VEPROMS.CSLA.Library
class extensionBase
{
// Default Values
public virtual DateTime DefaultDTS
{
get { return DateTime.Now; }
}
public virtual string DefaultUserID
{
get { return Volian.Base.Library.VlnSettings.UserID; }
}
public virtual DateTime DefaultDTS => DateTime.Now;
public virtual string DefaultUserID => Volian.Base.Library.VlnSettings.UserID;
// Authorization Rules
public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules)
{
@@ -1597,10 +1454,10 @@ namespace VEPROMS.CSLA.Library
{
public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType)
{
if (destType == typeof(string) && value is Content)
if (destType == typeof(string) && value is Content content)
{
// Return the ToString value
return ((Content)value).ToString();
return content.ToString();
}
return base.ConvertTo(context, culture, value, destType);
}
@@ -1608,46 +1465,3 @@ namespace VEPROMS.CSLA.Library
#endregion
} // Namespace
//// The following is a sample Extension File. You can use it to create ContentExt.cs
//using System;
//using System.Collections.Generic;
//using System.Text;
//using Csla;
//namespace VEPROMS.CSLA.Library
//{
// public partial class Content
// {
// partial class ContentExtension : extensionBase
// {
// // CSLATODO: Override automatic defaults
// public virtual DateTime DefaultDTS
// {
// get { return DateTime.Now; }
// }
// public virtual string DefaultUserID
// {
// 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 */);
// }
// }
// }
//}