Files
ayanova7/source/bizobjects/AyaLib/GZTW.AyaNova.BLL/UserSkillAssigned.cs
2018-06-29 19:47:36 +00:00

401 lines
9.1 KiB
C#

///////////////////////////////////////////////////////////
// UserSkillAssigned.cs
// Implementation of Class UserSkillAssigned
// CSLA type: Editable Child
// Created on: 07-Jun-2004 8:41:44 AM
// Object design: Joyce
// Coded: John 20-July-2004
///////////////////////////////////////////////////////////
using System;
using System.Data;
using CSLA.Data;
using CSLA;
using System.Threading;
using CSLA.Security;
using GZTW.Data;
namespace GZTW.AyaNova.BLL
{
/// <summary>
/// <see cref="UserSkill"/> assignement to <see cref="User"/>
/// </summary>
[Serializable]
public class UserSkillAssigned : BusinessBase
{
#region Attributes
private bool bReadOnly;
//Used only for keyword indexing
//and assigned docs collection
//primary key is user and certification ID combo
private Guid mID;
private Guid mCreator;
private Guid mModifier;
private SmartDate mCreated;
private SmartDate mModified;
private Guid mUserSkillID;
private Guid mUserID;
#endregion
#region Constructor
private UserSkillAssigned()
{
//Set to read / write initially so that properties
//can be set
bReadOnly=false;
//New ID - For assigned Docs list only
mID = Guid.NewGuid();
//Child object
MarkAsChild();
//Set record history to defaults
mCreated = new SmartDate(DBUtil.CurrentWorkingDateTime);
mModified=new SmartDate();
mCreator=Guid.Empty;
mModifier=Guid.Empty;
}
#endregion
#region BusinessProperties
//---Common properties
/// <summary>
/// Initial created date of this object
/// </summary>
public string Created
{
get
{
return mCreated.ToString();
}
}
/// <summary>
/// User ID of who initially created this object
/// </summary>
public Guid Creator
{
get
{
return mCreator;
}
}
/// <summary>
/// Last modified date of this object
/// </summary>
public string Modified
{
get
{
return mModified.ToString();
}
}
/// <summary>
/// User ID of who last modified this object
/// </summary>
public Guid Modifier
{
get
{
return mModifier;
}
}
/// <summary>
/// Unique ID of this object
/// </summary>
public Guid ID
{
get
{
return mID;
}
}
//---UserSkillAssigned specific properties
/// <summary>
/// User skill ID
/// </summary>
public Guid UserSkillID
{
get
{
return mUserSkillID;
}
set
{
if(bReadOnly)
ThrowSetError();
else
{
if(mUserSkillID!=value)
{
mUserSkillID = value;
MarkDirty();
}
}
}
}
/// <summary>
/// User ID
/// </summary>
public Guid UserID
{
get
{
return mUserID;
}
set
{
if(bReadOnly)
ThrowSetError();
else
{
if(mUserID!=value)
{
mUserID = value;
MarkDirty();
}
}
}
}
// /// <summary>
// /// Documents assigned to this object
// /// </summary>
// public AssignedDocs Docs
// {
// get
// {
// return mDocs;
// }
//
// }
/// <summary>
/// Throw an error when a read only user
/// tries to set a property
/// (this should normally never be called unless someone is using the developer api since the UI
/// should prevent it from happening initially)
/// </summary>
private void ThrowSetError()
{
throw new System.Security.SecurityException
(
string.Format
(
LocalizedTextTable.GetLocalizedTextDirect("Error.Security.NotAuthorizedToChange"),
LocalizedTextTable.GetLocalizedTextDirect("O.UserSkillAssigned")
)
);
}
#endregion
#region System.object overrides
/// <summary>
///
/// </summary>
/// <returns></returns>
public override string ToString()
{
return "UserSkillAssigned" + mUserSkillID.ToString()+mUserID.ToString();
}
/// <summary>
///
/// </summary>
/// <param name="obj"></param>
/// <returns></returns>
public override bool Equals(Object obj)
{
if ( obj == null || GetType ( ) != obj.GetType ( ) ) return false;
UserSkillAssigned c=(UserSkillAssigned)obj;
return ( (mUserSkillID==c.UserSkillID) && (mUserID==c.UserID) );
}
/// <summary>
///
/// </summary>
/// <returns></returns>
public override int GetHashCode()
{
return ("UserSkillAssigned" + mUserSkillID.ToString() + mUserID.ToString()).GetHashCode();
}
#endregion
#region Static methods
/// <summary>
/// NewItem
/// </summary>
/// <param name="obj"></param>
/// <returns></returns>
internal static UserSkillAssigned NewItem(User obj)
{
if (AyaBizUtils.Right("Object.UserSkillAssigned") > (int)SecurityLevelTypes.ReadOnly)
{
UserSkillAssigned child=new UserSkillAssigned();
child.UserSkillID=Guid.Empty;
child.UserID=obj.ID;
return child;
}
else
throw new System.Security.SecurityException(
string.Format(
LocalizedTextTable.GetLocalizedTextDirect("Error.Security.NotAuthorizedToCreate"),
LocalizedTextTable.GetLocalizedTextDirect("O.UserSkillAssigned")));
}
/// <summary>
/// Retrieve item
/// </summary>
/// <param name="dr">Data reader</param>
/// <returns>item from database</returns>
internal static UserSkillAssigned GetItem(SafeDataReader dr)
{
//case 1186
//if(AyaBizUtils.Right("Object.UserSkillAssigned")>(int)SecurityLevelTypes.NoAccess)
//{
UserSkillAssigned child = new UserSkillAssigned();
child.Fetch(dr);
return child;
//}
//else
// throw new System.Security.SecurityException(
// string.Format(
// LocalizedTextTable.GetLocalizedTextDirect("Error.Security.NotAuthorizedToRetrieve"),
// LocalizedTextTable.GetLocalizedTextDirect("O.UserSkillAssigned")));
}
#endregion
#region DAL Data Access
/// <summary>
/// Fetch from db
/// </summary>
/// <param name="dr"></param>
private void Fetch(SafeDataReader dr)
{
//Standard items
mCreated=DBUtil.ToLocal(dr.GetSmartDate("aCreated"));
mCreator=dr.GetGuid("aCreator");
mModified=DBUtil.ToLocal(dr.GetSmartDate("aModified"));
mModifier=dr.GetGuid("aModifier");
//UserSkillAssigned specific parameters
mUserSkillID=dr.GetGuid("aUserSkillID");
mUserID=dr.GetGuid("aUserID");
//required for assigned docs and
//keyword indexing
mID=dr.GetGuid("aID");
//Get access rights level
bReadOnly=AyaBizUtils.Right("Object.UserSkillAssigned")<(int)SecurityLevelTypes.ReadWrite;
MarkOld();
}
/// <summary>
/// Update
/// </summary>
/// <param name="obj"></param>
/// <param name="tr"></param>
internal void Update(User obj,IDbTransaction tr)
{
//No need to update if there is nothing changed
if(!this.IsDirty) return;
// If not a new record, check if record was modified
//by another user since original retrieval:
if(!IsNew)
DBUtil.CheckSafeToUpdate(this.mModified.Date,this.mID,"aUserSkillAssigned");
#region Delete
if(IsDeleted)
{
if(!IsNew)
{
DBCommandWrapper cmDelete = DBUtil.GetCommandFromSQL("DELETE FROM aUserSkillAssigned WHERE aID = @ID;");
cmDelete.AddInParameter("@ID",DbType.Guid,this.mID);
DBUtil.DB.ExecuteNonQuery(cmDelete, tr);
}
MarkNew();
return;
}
#endregion
#region Add / Update
//get modification time temporarily, if update succeeds then
//set to this time
System.DateTime dtModified = DBUtil.CurrentWorkingDateTime;
DBCommandWrapper cm = null;
if(IsNew)//Add or update?
cm=DBUtil.GetCommandFromSQL(
"INSERT INTO aUserSkillAssigned (aUserID, aUserSkillID, aID, aCreated, aModified, aCreator,aModifier) " +
"VALUES (@UserID,@UserSkillID,@ID,@Created,@Modified,@CurrentUserID,@CurrentUserID)"
);
else
cm=DBUtil.GetCommandFromSQL(
"UPDATE aUserSkillAssigned SET aUserID=@UserID, aUserSkillID=@UserSkillID, " +
"aID=@ID, aModifier=@CurrentUserID, " +
"aModified=@Modified where aID=@ID"
);
cm.AddInParameter("@ID",DbType.Guid, mID);
cm.AddInParameter("@UserID",DbType.Guid, mUserID);
cm.AddInParameter("@UserSkillID",DbType.Guid, mUserSkillID);
cm.AddInParameter("@CurrentUserID",DbType.Guid, CurrentUserID);
cm.AddInParameter("@Created",DbType.DateTime, DBUtil.ToUTC(mCreated).DBValue);
cm.AddInParameter("@Modified",DbType.DateTime, DBUtil.ToUTC(dtModified));
DBUtil.DB.ExecuteNonQuery(cm, tr);
MarkOld();//db is now synched with object
//Successful update so
//change modification time to match
this.mModified.Date=dtModified;
#endregion
}
#endregion
}//end UserSkillAssigned
}//end namespace GZTW.AyaNova.BLL