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

126 lines
3.1 KiB
C#

///////////////////////////////////////////////////////////
// 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
{
/// <summary>
/// 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)
///
/// </summary>
[Serializable]
public class ServiceBankCheckAlreadyBanked : ReadOnlyBase
{
private Guid mBankID=Guid.Empty;
#region Constructor
/// <summary>
/// Private constructor to prevent direct instantiation
/// </summary>
private ServiceBankCheckAlreadyBanked()
{
}
#endregion
#region Business properties
/// <summary>
/// ID of service bank entry if this object type and ID already has a bank entry
/// </summary>
public Guid BankID {get{return mBankID;}}
#endregion
#region Static methods
/// <summary>
/// Check if source object is already banked
/// </summary>
/// <param name="RootObjectID">ID of Bankable *source* object</param>
/// <param name="RootObjectType">Type of *source* object</param>
/// <returns>ID if already banked or Guid.Empty if not</returns>
public static Guid GetBankID(Guid RootObjectID, RootObjectTypes RootObjectType)
{
return ((ServiceBankCheckAlreadyBanked)DataPortal.Fetch(new Criteria(RootObjectID, RootObjectType))).mBankID;
}
#endregion
#region DAL DATA ACCESS
///
/// <param Bool="Criteria"></param>
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
/// <summary>
/// Criteria for identifying existing object
/// </summary>
[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