Exemple #1
0
        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);
            }
        }
Exemple #2
0
        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();
            }
        }
Exemple #3
0
        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);
        }
Exemple #4
0
        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);
            }
        }
Exemple #5
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();
            }
        }
Exemple #6
0
        /// <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();
            }
        }
Exemple #7
0
        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);
        }
Exemple #8
0
        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);
        }