///////////////////////////////////////////////////////////
// Implementation of Class ServiceBankCheckAlreadyBanked
// CSLA type: Read-only object
// Created on: 30-Sep-2009
// Object design: John
// Coded: John 30-Sep-2009
///////////////////////////////////////////////////////////
using System;
using System.Data;
using CSLA.Data;
using GZTW.Data;
using CSLA;
using System.Threading;
using CSLA.Security;
namespace GZTW.AyaNova.BLL
{
///
/// Used internally to quickly check if a bank entry has already been made for the source object type and id
/// and retrieve the bank ID if it is. This is generally used to avoid concurrency issues (another user banks an object moments before the current user does etc)
///
///
[Serializable]
public class ServiceBankCheckAlreadyBanked : ReadOnlyBase
{
private Guid mBankID=Guid.Empty;
#region Constructor
///
/// Private constructor to prevent direct instantiation
///
private ServiceBankCheckAlreadyBanked()
{
}
#endregion
#region Business properties
///
/// ID of service bank entry if this object type and ID already has a bank entry
///
public Guid BankID {get{return mBankID;}}
#endregion
#region Static methods
///
/// Check if source object is already banked
///
/// ID of Bankable *source* object
/// Type of *source* object
/// ID if already banked or Guid.Empty if not
public static Guid GetBankID(Guid RootObjectID, RootObjectTypes RootObjectType)
{
return ((ServiceBankCheckAlreadyBanked)DataPortal.Fetch(new Criteria(RootObjectID, RootObjectType))).mBankID;
}
#endregion
#region DAL DATA ACCESS
///
///
protected override void DataPortal_Fetch(object Criteria)
{
Criteria crit = (Criteria)Criteria;
DBCommandWrapper cm = DBUtil.DB.GetSqlStringCommandWrapper(
"SELECT AID " +
"FROM aServiceBank WHERE (ASOURCEROOTOBJECTID " +
"= @ID AND ASOURCEROOTOBJECTTYPE = @RootObjectType) "
);
cm.AddInParameter("@ID", DbType.Guid, crit.RootObjectID);
cm.AddInParameter("@RootObjectType", DbType.Int16, (int)crit.RootObjectType);
SafeDataReader dr = new SafeDataReader(DBUtil.DB.ExecuteReader(cm));
mBankID = Guid.Empty;
if(dr.Read())
{
mBankID=dr.GetGuid("AID");
}
dr.Close();
}
#endregion
#region criteria
///
/// Criteria for identifying existing object
///
[Serializable]
private class Criteria
{
public Guid RootObjectID;
public RootObjectTypes RootObjectType;
public Criteria(Guid _RootObjectID, RootObjectTypes _RootObjectType)
{
RootObjectID=_RootObjectID;
RootObjectType=_RootObjectType;
}
}
#endregion
}//end Bool
}//end Boolspace GZTW.AyaNova.BLL