392 lines
9.5 KiB
C#
392 lines
9.5 KiB
C#
///////////////////////////////////////////////////////////
|
|
// ScheduleableUserGroupUser.cs
|
|
// Implementation of Class ScheduleableUserGroupUser
|
|
// CSLA type: Editable Child
|
|
// Created on: 29-July-2004
|
|
// Object design: John
|
|
// Coded: John 29-July-2004
|
|
///////////////////////////////////////////////////////////
|
|
|
|
using System;
|
|
using System.Data;
|
|
using CSLA.Data;
|
|
using GZTW.Data;
|
|
using CSLA;
|
|
using System.Threading;
|
|
using CSLA.Security;
|
|
|
|
namespace GZTW.AyaNova.BLL
|
|
{
|
|
/// <summary>
|
|
/// Individual ScheduleableUser assignment to a ScheduleableUser group
|
|
/// </summary>
|
|
[Serializable]
|
|
public class ScheduleableUserGroupUser : BusinessBase
|
|
{
|
|
|
|
#region Attributes
|
|
|
|
private bool bReadOnly;
|
|
|
|
private Guid mID;
|
|
private Guid mCreator;
|
|
private Guid mModifier;
|
|
private SmartDate mCreated;
|
|
private SmartDate mModified;
|
|
|
|
private Guid mScheduleableUserID;
|
|
/// <summary>
|
|
/// ID of ScheduleableUserGroup this ScheduleableUser belongs with
|
|
/// </summary>
|
|
private Guid mScheduleableUserGroupID;
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
#region Constructor
|
|
private ScheduleableUserGroupUser()
|
|
{
|
|
//Set to read / write initially so that properties
|
|
//can be set
|
|
bReadOnly=false;
|
|
|
|
//Child object
|
|
MarkAsChild();
|
|
|
|
//New ID
|
|
mID = Guid.NewGuid();
|
|
|
|
//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;
|
|
}
|
|
}
|
|
|
|
|
|
//---ScheduleableUserGroupUser specific properties
|
|
|
|
|
|
/// <summary>
|
|
/// ID of the <see cref="User"/> who is scheduled
|
|
/// </summary>
|
|
public Guid ScheduleableUserID
|
|
{
|
|
get
|
|
{
|
|
return mScheduleableUserID;
|
|
}
|
|
set
|
|
{
|
|
if(bReadOnly)
|
|
ThrowSetError();
|
|
else
|
|
{
|
|
//TODO: Ensure that only a scheduleable user was added
|
|
|
|
if(mScheduleableUserID!=value)
|
|
{
|
|
mScheduleableUserID = value;
|
|
MarkDirty();
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// ID of ScheduleableUserGroup this ScheduleableUser belongs with
|
|
/// </summary>
|
|
public Guid ScheduleableUserGroupID
|
|
{
|
|
get
|
|
{
|
|
return mScheduleableUserGroupID;
|
|
}
|
|
set
|
|
{
|
|
if(bReadOnly)
|
|
ThrowSetError();
|
|
else
|
|
{
|
|
if(mScheduleableUserGroupID!=value)
|
|
{
|
|
mScheduleableUserGroupID = value;
|
|
MarkDirty();
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
/// <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.ScheduleableUserGroupUser")
|
|
)
|
|
);
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region System.object overrides
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public override string ToString()
|
|
{
|
|
return "ScheduleableUserGroupUser" + mID.ToString();
|
|
}
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="obj"></param>
|
|
/// <returns></returns>
|
|
public override bool Equals(Object obj)
|
|
{
|
|
if ( obj == null || GetType ( ) != obj.GetType ( ) ) return false;
|
|
ScheduleableUserGroupUser c=(ScheduleableUserGroupUser)obj;
|
|
return mID==c.mID;
|
|
}
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public override int GetHashCode()
|
|
{
|
|
return ("ScheduleableUserGroupUser" + mID).GetHashCode();
|
|
}
|
|
#endregion
|
|
|
|
#region Static methods
|
|
/// <summary>
|
|
/// Create item
|
|
/// </summary>
|
|
/// <param name="obj">Parent ID</param>
|
|
/// <returns>New Item</returns>
|
|
internal static ScheduleableUserGroupUser NewItem(ScheduleableUserGroup obj)
|
|
{
|
|
|
|
if(AyaBizUtils.Right("Object.ScheduleableUserGroupUser")>(int)SecurityLevelTypes.ReadOnly)
|
|
{
|
|
ScheduleableUserGroupUser child=new ScheduleableUserGroupUser();
|
|
child.ScheduleableUserID=Guid.Empty;
|
|
child.mScheduleableUserGroupID=obj.ID;
|
|
return child;
|
|
}
|
|
else
|
|
throw new System.Security.SecurityException(
|
|
string.Format(
|
|
LocalizedTextTable.GetLocalizedTextDirect("Error.Security.NotAuthorizedToCreate"),
|
|
LocalizedTextTable.GetLocalizedTextDirect("O.ScheduleableUserGroupUser")));
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// Retrieve item
|
|
/// </summary>
|
|
/// <param name="dr">Data reader</param>
|
|
/// <returns>item from database</returns>
|
|
internal static ScheduleableUserGroupUser GetItem(SafeDataReader dr)
|
|
{
|
|
|
|
|
|
if(AyaBizUtils.Right("Object.ScheduleableUserGroupUser")>(int)SecurityLevelTypes.NoAccess)
|
|
{
|
|
ScheduleableUserGroupUser child = new ScheduleableUserGroupUser();
|
|
child.Fetch(dr);
|
|
return child;
|
|
}
|
|
else
|
|
throw new System.Security.SecurityException(
|
|
string.Format(
|
|
LocalizedTextTable.GetLocalizedTextDirect("Error.Security.NotAuthorizedToRetrieve"),
|
|
LocalizedTextTable.GetLocalizedTextDirect("O.ScheduleableUserGroupUser")));
|
|
}
|
|
#endregion
|
|
|
|
#region DAL DATA ACCESS
|
|
|
|
#region Fetch
|
|
/// <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");
|
|
mID=dr.GetGuid("aID");
|
|
|
|
//ScheduleableUserGroupUser specific parameters
|
|
mScheduleableUserID=dr.GetGuid("aScheduleableUserID");
|
|
mScheduleableUserGroupID=dr.GetGuid("aScheduleableUserGroupID");
|
|
|
|
//Get access rights level
|
|
bReadOnly=AyaBizUtils.Right("Object.ScheduleableUserGroupUser")<(int)SecurityLevelTypes.ReadWrite;
|
|
|
|
MarkOld();
|
|
|
|
}
|
|
#endregion
|
|
|
|
#region Update
|
|
|
|
/// <summary>
|
|
/// Persist object to database
|
|
/// </summary>
|
|
/// <param name="obj">Parent object</param>
|
|
/// <param name="tr">Parents transaction object</param>
|
|
internal void Update(ScheduleableUserGroup 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,"aScheduleableUserGroupUser");
|
|
|
|
#region Delete
|
|
if(IsDeleted)
|
|
{
|
|
if(!IsNew)
|
|
{
|
|
//Delete object and child objects
|
|
DBCommandWrapper cmDelete = DBUtil.GetCommandFromSQL("DELETE FROM aScheduleableUserGroupUser 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 aScheduleableUserGroupUser (aScheduleableUserID, " +
|
|
"aID, aScheduleableUserGroupID, aCreated,aModified,aCreator, " +
|
|
"aModifier) VALUES (@ScheduleableUserID,@ID,@ScheduleableUserGroupID, " +
|
|
"@Created,@Modified,@CurrentUserID,@CurrentUserID)"
|
|
);
|
|
else
|
|
cm=DBUtil.GetCommandFromSQL(
|
|
"UPDATE aScheduleableUserGroupUser SET aScheduleableUserID=@ScheduleableUserID, " +
|
|
"aID=@ID, aScheduleableUserGroupID=@ScheduleableUserGroupID, " +
|
|
"aModifier=@CurrentUserID, " +
|
|
"aModified=@Modified WHERE aID=@ID"
|
|
);
|
|
|
|
|
|
//ScheduleableUserGroupUser specific parameters
|
|
cm.AddInParameter("@ID",DbType.Guid,this.mID);
|
|
cm.AddInParameter("@ScheduleableUserID",DbType.Guid,mScheduleableUserID);
|
|
cm.AddInParameter("@ScheduleableUserGroupID",DbType.Guid,mScheduleableUserGroupID);
|
|
|
|
//Standard fields
|
|
cm.AddInParameter("@CurrentUserID",DbType.Guid, CurrentUserID);
|
|
cm.AddInParameter("@Created",DbType.DateTime, DBUtil.ToUTC(mCreated.Date));
|
|
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 update
|
|
|
|
#endregion
|
|
|
|
}//end ScheduleableUserGroupUser
|
|
|
|
}//end namespace GZTW.AyaNova.BLL
|