/////////////////////////////////////////////////////////// // 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 { /// /// assignement to /// [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 /// /// Initial created date of this object /// public string Created { get { return mCreated.ToString(); } } /// /// User ID of who initially created this object /// public Guid Creator { get { return mCreator; } } /// /// Last modified date of this object /// public string Modified { get { return mModified.ToString(); } } /// /// User ID of who last modified this object /// public Guid Modifier { get { return mModifier; } } /// /// Unique ID of this object /// public Guid ID { get { return mID; } } //---UserSkillAssigned specific properties /// /// User skill ID /// public Guid UserSkillID { get { return mUserSkillID; } set { if(bReadOnly) ThrowSetError(); else { if(mUserSkillID!=value) { mUserSkillID = value; MarkDirty(); } } } } /// /// User ID /// public Guid UserID { get { return mUserID; } set { if(bReadOnly) ThrowSetError(); else { if(mUserID!=value) { mUserID = value; MarkDirty(); } } } } // /// // /// Documents assigned to this object // /// // public AssignedDocs Docs // { // get // { // return mDocs; // } // // } /// /// 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) /// private void ThrowSetError() { throw new System.Security.SecurityException ( string.Format ( LocalizedTextTable.GetLocalizedTextDirect("Error.Security.NotAuthorizedToChange"), LocalizedTextTable.GetLocalizedTextDirect("O.UserSkillAssigned") ) ); } #endregion #region System.object overrides /// /// /// /// public override string ToString() { return "UserSkillAssigned" + mUserSkillID.ToString()+mUserID.ToString(); } /// /// /// /// /// 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) ); } /// /// /// /// public override int GetHashCode() { return ("UserSkillAssigned" + mUserSkillID.ToString() + mUserID.ToString()).GetHashCode(); } #endregion #region Static methods /// /// NewItem /// /// /// 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"))); } /// /// Retrieve item /// /// Data reader /// item from database 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 /// /// Fetch from db /// /// 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(); } /// /// Update /// /// /// 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