public int UpdateStoreSetting(StoreSettingObject storeSetting)
 {
     try
     {
         if (storeSetting == null)
         {
             return(-2);
         }
         var duplicates = _repository.Count(m => m.StoreId == storeSetting.StoreId && (m.StoreId != storeSetting.StoreId));
         if (duplicates > 0)
         {
             return(-3);
         }
         var storeSettingEntity = ModelCrossMapper.Map <StoreSettingObject, StoreSetting>(storeSetting);
         if (storeSettingEntity == null || storeSettingEntity.StoreId < 1)
         {
             return(-2);
         }
         _repository.Update(storeSettingEntity);
         _uoWork.SaveChanges();
         return(5);
     }
     catch (Exception ex)
     {
         ErrorLogger.LogError(ex.StackTrace, ex.Source, ex.Message);
         return(-2);
     }
 }
Example #2
0
 public static string SwitchSqlDatabase(StoreSettingObject storeSetings)
 {
     try
     {
         return(DbContextSwitcher.SwitchSqlDatabase(storeSetings));
     }
     catch (Exception ex)
     {
         ErrorLogger.LogError(ex.StackTrace, ex.Source, ex.Message);
         return(string.Empty);
     }
 }
 public int UpdateStoreSetting(StoreSettingObject storeSetting)
 {
     try
     {
         return(_storeSettingRepository.UpdateStoreSetting(storeSetting));
     }
     catch (Exception ex)
     {
         ErrorLogger.LogError(ex.StackTrace, ex.Source, ex.Message);
         return(-2);
     }
 }
Example #4
0
        public static StoreSettingObject GetConnectionStringParameters()
        {
            try
            {
                var sqlCnxStringBuilder = new SqlConnectionStringBuilder(ConfigurationManager.ConnectionStrings["DynamicConnection"].ConnectionString);
                if (string.IsNullOrEmpty(sqlCnxStringBuilder.ConnectionString))
                {
                    return(new StoreSettingObject());
                }

                var dbScriptPath = ConfigurationManager.AppSettings["DBScriptPath"];
                if (string.IsNullOrEmpty(dbScriptPath))
                {
                    return(new StoreSettingObject());
                }

                var domainExtension = ConfigurationManager.AppSettings["domainExtension"];
                if (string.IsNullOrEmpty(domainExtension))
                {
                    return(new StoreSettingObject());
                }

                var k = new StoreSettingObject
                {
                    InitialCatalog      = sqlCnxStringBuilder.InitialCatalog,
                    DataSource          = sqlCnxStringBuilder.DataSource,
                    UserName            = sqlCnxStringBuilder.UserID,
                    StorePsswd          = sqlCnxStringBuilder.Password,
                    DBScriptPath        = dbScriptPath,
                    SqlConnectionString = sqlCnxStringBuilder.ConnectionString,
                    DomainExtension     = domainExtension
                };

                return(k);
            }

            catch (Exception ex)
            {
                ErrorLogger.LogError(ex.StackTrace, ex.Source, ex.Message);
                return(new StoreSettingObject());
            }
        }
Example #5
0
        public static string SwitchSqlDatabase(StoreSettingObject storeSetings)
        {
            try
            {
                if (string.IsNullOrEmpty(storeSetings.InitialCatalog) || string.IsNullOrWhiteSpace(storeSetings.InitialCatalog))
                {
                    return(string.Empty);
                }

                var cnfigManager        = ConfigurationManager.ConnectionStrings["DynamicConnection"];
                var sqlCnxStringBuilder = new SqlConnectionStringBuilder(cnfigManager.ConnectionString);

                if (!string.IsNullOrEmpty(storeSetings.InitialCatalog))
                {
                    sqlCnxStringBuilder.InitialCatalog = storeSetings.InitialCatalog;
                }
                if (!string.IsNullOrEmpty(storeSetings.DataSource))
                {
                    sqlCnxStringBuilder.DataSource = storeSetings.DataSource;
                }
                if (!string.IsNullOrEmpty(storeSetings.UserName))
                {
                    sqlCnxStringBuilder.UserID = storeSetings.UserName;
                }
                if (!string.IsNullOrEmpty(storeSetings.StorePsswd))
                {
                    sqlCnxStringBuilder.Password = storeSetings.StorePsswd;
                }

                sqlCnxStringBuilder.IntegratedSecurity       = true;
                sqlCnxStringBuilder.MultipleActiveResultSets = true;
                return(sqlCnxStringBuilder.ToString());
            }

            catch (Exception ex)
            {
                ErrorLogger.LogError(ex.StackTrace, ex.Source, ex.Message);
                return(null);
            }
        }
Example #6
0
        public static string SwitchEntityDatabase(StoreSettingObject storeSetings)
        {
            try
            {
                if (string.IsNullOrEmpty(storeSetings.InitialCatalog) || string.IsNullOrWhiteSpace(storeSetings.InitialCatalog))
                {
                    return(string.Empty);
                }

                var entityCnxStringBuilder = new EntityConnectionStringBuilder(ConfigurationManager.ConnectionStrings["ShopKeeperStoreEntities"].ConnectionString);

                var sqlCnxStringBuilder = new SqlConnectionStringBuilder(entityCnxStringBuilder.ProviderConnectionString);

                if (!string.IsNullOrEmpty(storeSetings.InitialCatalog))
                {
                    sqlCnxStringBuilder.InitialCatalog = storeSetings.InitialCatalog;
                }
                if (!string.IsNullOrEmpty(storeSetings.DataSource))
                {
                    sqlCnxStringBuilder.DataSource = storeSetings.DataSource;
                }
                if (!string.IsNullOrEmpty(storeSetings.UserName))
                {
                    sqlCnxStringBuilder.UserID = storeSetings.UserName;
                }
                if (!string.IsNullOrEmpty(storeSetings.StorePsswd))
                {
                    sqlCnxStringBuilder.Password = storeSetings.StorePsswd;
                }

                entityCnxStringBuilder.ProviderConnectionString = sqlCnxStringBuilder.ToString();
                return(entityCnxStringBuilder.ToString());
            }

            catch (Exception ex)
            {
                ErrorLogger.LogError(ex.StackTrace, ex.Source, ex.Message);
                return(null);
            }
        }
Example #7
0
        private StoreSettingObject GetStoreInfo(string subdomain)
        {
            try
            {
                var domainOj = new StoreSettingObject();

                if (Session["_mySettings"] == null)
                {
                    domainOj = new StoreSettingServices().GetStoreSettingByAlias(subdomain);

                    if (domainOj.StoreId < 1)
                    {
                        return(null);
                    }

                    var connection = DbContextSwitcherServices.SwitchSqlDatabase(domainOj);

                    if (string.IsNullOrEmpty(connection))
                    {
                        return(null);
                    }
                    domainOj.SqlConnectionString = connection;
                    Session["_mySettings"]       = domainOj;
                    return(domainOj);
                }
                else
                {
                    var sessDom = Session["_mySettings"] as StoreSettingObject;
                    if (sessDom == null || sessDom.StoreId < 1)
                    {
                        return(null);
                    }
                    return(domainOj);
                }
            }
            catch (Exception)
            {
                return(null);
            }
        }