public IDataBase GetDataBaseById(int dataBaseId) { if (dataBaseId == 0) { ExceptionFactory.BusinessLogicException.AddMessage("DataBase Id Cannot Be Zero").Raise(); } TenantSession tenantSession = new TenantSession(); ISession session = tenantSession.GetTenantSession(); ICriteria crit = session.CreateCriteria(typeof(DataBase)); crit.Add(Expression.Eq("Id", dataBaseId)); try { DataBase dataBase = crit.UniqueResult <DataBase>(); if (dataBase == null) { ExceptionFactory.BusinessLogicException.AddMessage("No DatBase Exist With This Id").Raise(); } return(dataBase as IDataBase); } catch (System.Exception ex) { ExceptionFactory.BusinessLogicException.AddMessage("Error In GetDataBaseById").Raise(); return(null); } }
public void UpdateDataBase(IDataBase dataBase) { if (dataBase != null) { if (dataBase.Id == 0) { ExceptionFactory.BusinessLogicException.AddMessage("DataBase Id Cannot Be Zero").Raise(); } if (string.IsNullOrEmpty(dataBase.DBConfiguration) || string.IsNullOrEmpty(dataBase.Name) || dataBase.DBType == EnumDB.None) { ExceptionFactory.BusinessLogicException.AddMessage("DBConfiguration,Name & DBType Fields Are Mandatory").Raise(); } TenantSession tenantSession = new TenantSession(); ISession session = tenantSession.GetTenantSession(); DataBase dBase = (DataBase)dataBase; try { session.Update(dBase); session.Flush(); } catch (System.Exception ex) { ExceptionFactory.BusinessLogicException.AddMessage("Error In Updating DataBase Object").Raise(); } } else { ExceptionFactory.BusinessLogicException.AddMessage("DataBase Object Is Null").Raise(); } }
public List <IDataBase> GetAllDataBases() { TenantSession tenantSession = new TenantSession(); ISession sessionTenantDB = tenantSession.GetTenantSession(); //5.Get DatabaseInfo ICriteria crit = sessionTenantDB.CreateCriteria(typeof(DataBase)); crit.Add(Expression.Eq("IsDeleted", false)); ICollection <DataBase> dataBases = null; try { dataBases = crit.List <DataBase>(); } catch (System.Exception ex) { ExceptionFactory.BusinessLogicException.AddMessage("Error In Getting DataBase Objects").Raise(); } List <IDataBase> dBases = new List <IDataBase>(); if (dataBases != null && dataBases.Count != 0) { foreach (DataBase db in dataBases) { dBases.Add(db); } } return(dBases); }
public int CreateDataBase(IDataBase dataBase) { if (dataBase != null) { if (string.IsNullOrEmpty(dataBase.DBConfiguration) || string.IsNullOrEmpty(dataBase.Name) || dataBase.DBType == EnumDB.None) { ExceptionFactory.BusinessLogicException.AddMessage("DBConfiguration,Name & DBType Fields Are Mandatory").Raise(); } TenantSession tenantSession = new TenantSession(); ISession session = tenantSession.GetTenantSession(); DataBase dBase = (DataBase)dataBase; try { session.Save(dBase); session.Flush(); } catch (System.Exception ex) { ExceptionFactory.BusinessLogicException.AddMessage("Error In Saving DataBase").Raise(); } return(dBase.Id); } else { ExceptionFactory.BusinessLogicException.AddMessage("DataBase Object Is Null").Raise(); return(0); } }
/// <summary> /// CreateTenantDataBase /// </summary> public void CreateTenantDataBase(int dataBaseId, int tenantId) { if (dataBaseId == 0) { ExceptionFactory.BusinessLogicException.AddMessage("DataBase Id Cannot Be Zero").Raise(); } if (tenantId == 0) { ExceptionFactory.BusinessLogicException.AddMessage("TenantId Id Cannot Be Zero").Raise(); } TenantSession tenantSession = new TenantSession(); ISession session = tenantSession.GetTenantSession(); try { //Check Already DataBase Configured For This Tenant ICriteria crit = session.CreateCriteria(typeof(DataBaseTenant)); crit.Add(Expression.Eq("TenantId", tenantId)); DataBaseTenant dataBaseTenant = crit.UniqueResult <DataBaseTenant>(); if (dataBaseTenant != null) { ExceptionFactory.BusinessLogicException.AddMessage("DatBase Already Configured For This Tenant").Raise(); } //Check For Valid DataBaseId crit = session.CreateCriteria(typeof(DataBase)); crit.Add(Expression.Eq("Id", dataBaseId)); DataBase dataBase = crit.UniqueResult <DataBase>(); if (dataBase == null) { ExceptionFactory.BusinessLogicException.AddMessage("InValid DataBaseId").Raise(); } dataBaseTenant = new DataBaseTenant(); dataBaseTenant.DataBaseId = dataBaseId; dataBaseTenant.TenantId = tenantId; session.Save(dataBaseTenant); session.Flush(); } catch (System.Exception ex) { ExceptionFactory.BusinessLogicException.AddMessage("Error In CreateTenantDataBase").Raise(); } }
/// <summary> /// UpdateTenantDataBase /// </summary> public void UpdateTenantDataBase(int modifiedDataBaseId, int tenantId) { if (modifiedDataBaseId == 0) { ExceptionFactory.BusinessLogicException.AddMessage("modifiedDataBaseId Cannot Be Zero").Raise(); } if (tenantId == 0) { ExceptionFactory.BusinessLogicException.AddMessage("TenantId Id Cannot Be Zero").Raise(); } TenantSession tenantSession = new TenantSession(); ISession session = tenantSession.GetTenantSession(); try { //Check For Valid DataBaseId ICriteria crit = session.CreateCriteria(typeof(DataBase)); crit.Add(Expression.Eq("Id", modifiedDataBaseId)); DataBase dataBase = crit.UniqueResult <DataBase>(); if (dataBase == null) { ExceptionFactory.BusinessLogicException.AddMessage("InValid DataBaseId").Raise(); } //Get DataBaseTenant By TenantId crit = session.CreateCriteria(typeof(DataBaseTenant)); crit.Add(Expression.Eq("TenantId", tenantId)); DataBaseTenant dataBaseTenant = crit.UniqueResult <DataBaseTenant>(); if (dataBaseTenant == null) { ExceptionFactory.BusinessLogicException.AddMessage("Invalid TenantId").Raise(); } dataBaseTenant.DataBaseId = modifiedDataBaseId; session.Update(dataBaseTenant); session.Flush(); } catch (System.Exception ex) { ExceptionFactory.BusinessLogicException.AddMessage("Error In UpdateTenantDataBase").Raise(); } }
private ICollection <DataBase> GetDataBaseList() { //1.Get Tenant DB Session TenantSession tenantSession = new TenantSession(); ISession sessionTenantDB = tenantSession.GetTenantSession(); //2.Get DatabaseInfo ICriteria crit = sessionTenantDB.CreateCriteria(typeof(DataBase)); crit.Add(Expression.Eq("IsDeleted", false)); ICollection <DataBase> dataBases = crit.List <DataBase>(); if (dataBases == null && dataBases.Count == 0) { ExceptionFactory.DataAccessException.AddMessage("DataBase Info Not Found In Tenant DB").Raise(); } //5.Close TenantDB session sessionTenantDB.Close(); return(dataBases); }
private ICollection <DataBaseTenant> GetTenantDataBaseList() { //1.Get Tenant DB Session TenantSession tenantSession = new TenantSession(); ISession sessionTenantDB = tenantSession.GetTenantSession(); //3.Get TenantDatabaseInfo ICriteria crit = sessionTenantDB.CreateCriteria(typeof(DataBaseTenant)); crit.Add(Expression.Eq("IsDeleted", false)); ICollection <DataBaseTenant> dataBaseTenants = crit.List <DataBaseTenant>(); if (dataBaseTenants == null || dataBaseTenants.Count == 0) { ExceptionFactory.DataAccessException.AddMessage("DataBaseTenant Info Not Found In Tenant DB").Raise(); } ////4.Assign DatABaseConfig Info //List<DataBaseTenant> listDataBaseTenants = new List<DataBaseTenant>(); //foreach (DataBase dataBase in dataBases) //{ // foreach (DataBaseTenant dataBaseTenant in dataBaseTenants) // { // if (dataBaseTenant.DataBaseId == dataBase.Id) // { // dataBaseTenant.DBConfiguration = dataBase.DBConfiguration; // listDataBaseTenants.Add(dataBaseTenant); // } // } //} //5.Close TenantDB session sessionTenantDB.Close(); return(dataBaseTenants); }