Пример #1
0
        private StoreSettingObject GetInfo(string subdomain)
        {
            try
            {
                if (string.IsNullOrEmpty(subdomain))
                {
                    return(new StoreSettingObject());
                }

                var domainOj = new StoreSettingServices().GetStoreSettingByAlias(subdomain);

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

                var sqlConnection    = DbContextSwitcherServices.SwitchSqlDatabase(domainOj);
                var entityConnection = DbContextSwitcherServices.SwitchEntityDatabase(domainOj);

                if (string.IsNullOrEmpty(sqlConnection) || string.IsNullOrEmpty(entityConnection))
                {
                    return(new StoreSettingObject());
                }

                domainOj.EntityConnectionString = entityConnection;
                domainOj.SqlConnectionString    = sqlConnection;
                domainOj.StoreLogoPath          = string.IsNullOrEmpty(domainOj.StoreLogoPath) ? "/Content/images/noImage.png" : domainOj.StoreLogoPath.Replace("~", "");
                SetCurrentSession("mySetting", domainOj);

                var defaultCurrency = new StoreItemStockServices().GetStoreDefaultCurrency();
                if (defaultCurrency != null && defaultCurrency.StoreCurrencyId > 0)
                {
                    domainOj.DefaultCurrency       = defaultCurrency.Name;
                    domainOj.DefaultCurrencySymbol = defaultCurrency.Symbol;
                }

                return(domainOj);
            }
            catch (Exception)
            {
                return(new StoreSettingObject());
            }
        }
Пример #2
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);
            }
        }
Пример #3
0
        private bool CreateDB(string dbName, StoreObject store)
        {
            try
            {
                var storeSettings = DbContextSwitcherServices.GetConnectionStringParameters();
                if (storeSettings == null || string.IsNullOrEmpty(storeSettings.DataSource))
                {
                    return(false);
                }

                //storeSettings.InitialCatalog = dbName;

                var storageSpace = store.StorageSize / 2;
                var dbObject     = new DBObject
                {
                    DBSize           = storageSpace,
                    DBName           = dbName,
                    ConnectionString = storeSettings.SqlConnectionString,
                    ScriptFilePath   = Server.MapPath(storeSettings.DBScriptPath)
                };

                var dbCreationResult = DBCreator.CreateDB(dbObject);
                if (!dbCreationResult)
                {
                    return(false);
                }

                storeSettings.StoreId        = store.StoreId;
                storeSettings.InitialCatalog = dbName;

                var k = AddStoreSettings(storeSettings);
                if (k < 1)
                {
                    return(false);
                }

                var subscriptionSetting = new SubscriptionSettingObject
                {
                    StoreId          = store.StoreId,
                    SecreteKey       = store.SecreteKey,
                    DatabaseSpace    = storageSpace,
                    FileStorageSpace = storageSpace,
                    Url                = store.StoreAlias.ToLower().Trim() + storeSettings.DomainExtension,
                    DateSubscribed     = DateTime.Today,
                    ExpiryDate         = DateTime.Today.AddDays(store.Duration),
                    SubscriptionStatus = store.SubscriptionStatus,
                };

                var connectionString = DbContextSwitcherServices.SwitchEntityDatabase(storeSettings);
                if (string.IsNullOrEmpty(storeSettings.DataSource))
                {
                    return(false);
                }

                _dbConnection    = connectionString;
                _domainExtension = storeSettings.DomainExtension;
                Session["entityConnectionString"]   = connectionString;
                Session["identityconnectionString"] = dbObject.ConnectionString.Replace("master", dbName);
                var result = new SubscriptionSettingServices(connectionString).AddSubscriptionSetting(subscriptionSetting);
                if (result < 1)
                {
                    return(false);
                }

                var storPath = CreateStoreDirectory("~/Stores/" + dbName + "/Assets");
                return(storPath);
            }
            catch (Exception e)
            {
                ErrorLogger.LogError(e.StackTrace, e.Source, e.Message);
                return(false);
            }
        }