Example #1
0
        public void UpdateSetting(
            string formKey,
            string settingName,
            object settings,
            FormCollection form,
            int storeId,
            ISettingService settingService,
            ILocalizedModelLocal localized = null)
        {
            if (storeId == 0 || IsOverrideChecked(formKey, form))
            {
                var prop = FastProperty.GetProperty(localized == null ? settings.GetType() : localized.GetType(), settingName);
                if (prop != null)
                {
                    dynamic value = prop.GetValue(localized == null ? settings : localized);
                    var     key   = string.Concat(settings.GetType().Name, ".", settingName);

                    settingService.SetSetting(key, value == null ? "" : value, storeId, false);
                }
            }
            else if (storeId > 0)
            {
                var key = string.Concat(settings.GetType().Name, ".", settingName);
                settingService.DeleteSetting(key, storeId);
            }
        }
Example #2
0
        public void GetOverrideKey(
            string formKey,
            string settingName,
            object settings,
            int storeId,
            ISettingService settingService,
            ILocalizedModelLocal localized = null,
            int?index = null)
        {
            if (storeId <= 0)
            {
                // Single store mode -> there are no overrides.
                return;
            }

            var data    = Data ?? new StoreDependingSettingData();
            var setting = string.Empty;

            if (localized == null)
            {
                var key = string.Concat(settings.GetType().Name, ".", settingName);
                setting = settingService.GetSettingByKey <string>(key, storeId: storeId);
            }
            else
            {
                // TODO if required
                throw new ArgumentException("Localized override key not supported yet.");
            }

            if (!string.IsNullOrEmpty(setting))
            {
                data.OverrideSettingKeys.Add(formKey);
            }
        }
        /// <summary>
        /// Updates settings for a store.
        /// </summary>
        /// <param name="settings">Settings class instance.</param>
        /// <param name="form">Form value collection.</param>
        /// <param name="storeId">Store identifier.</param>
        /// <param name="settingService">Setting service.</param>
        /// <param name="localized">Localized model.</param>
        /// <param name="propertyNameMapper">Function to map property names. Return <c>null</c> to skip a property.</param>
        public void UpdateSettings(
            object settings,
            FormCollection form,
            int storeId,
            ISettingService settingService,
            ILocalizedModelLocal localized           = null,
            Func <string, string> propertyNameMapper = null)
        {
            var settingName = settings.GetType().Name;
            var properties  = FastProperty.GetProperties(localized == null ? settings.GetType() : localized.GetType()).Values;

            foreach (var prop in properties)
            {
                var name = prop.Name;

                if (propertyNameMapper != null)
                {
                    name = propertyNameMapper(name);
                }

                if (string.IsNullOrWhiteSpace(name))
                {
                    continue;
                }

                var key = string.Concat(settingName, ".", name);

                if (storeId == 0 || IsOverrideChecked(key, form))
                {
                    dynamic value = prop.GetValue(localized == null ? settings : localized);
                    settingService.SetSetting(key, value == null ? "" : value, storeId, false);
                }
                else if (storeId > 0)
                {
                    settingService.DeleteSetting(key, storeId);
                }
            }
        }
        public void GetOverrideKeys(object settings, object model, int storeId, ISettingService settingService, bool isRootModel = true, ILocalizedModelLocal localized = null, int?index = null)
        {
            if (storeId <= 0)
            {
                return;         // single store mode -> there are no overrides
            }
            var data = Data;

            if (data == null)
            {
                data = new StoreDependingSettingData();
            }

            var settingName            = settings.GetType().Name;
            var properties             = settings.GetType().GetProperties();
            var localizedEntityService = EngineContext.Current.Resolve <ILocalizedEntityService>();

            var modelType = model.GetType();

            foreach (var prop in properties)
            {
                var name          = prop.Name;
                var modelProperty = modelType.GetProperty(name);

                if (modelProperty == null)
                {
                    continue;   // setting is not configurable or missing or whatever... however we don't need the override info
                }
                var key     = String.Empty;
                var setting = String.Empty;

                if (localized == null)
                {
                    key     = settingName + "." + name;
                    setting = settingService.GetSettingByKey <string>(key, storeId: storeId);
                }
                else
                {
                    key     = "Locales[" + index.ToString() + "]." + name;
                    setting = localizedEntityService.GetLocalizedValue(localized.LanguageId, 0, settingName, name);
                }

                if (!String.IsNullOrEmpty(setting))
                {
                    data.OverrideSettingKeys.Add(key);
                }
            }

            if (isRootModel)
            {
                data.ActiveStoreScopeConfiguration = storeId;
                data.RootSettingClass = settingName;

                _viewData[ViewDataKey] = data;
            }
        }
        public void UpdateSettings(object settings, FormCollection form, int storeId, ISettingService settingService, ILocalizedModelLocal localized = null)
        {
            var settingName = settings.GetType().Name;
            var properties  = FastProperty.GetProperties(localized == null ? settings.GetType() : localized.GetType()).Values;

            foreach (var prop in properties)
            {
                var name = prop.Name;
                var key  = settingName + "." + name;

                if (storeId == 0 || IsOverrideChecked(key, form))
                {
                    dynamic value = prop.GetValue(localized == null ? settings : localized);
                    settingService.SetSetting(key, value == null ? "" : value, storeId, false);
                }
                else if (storeId > 0)
                {
                    settingService.DeleteSetting(key, storeId);
                }
            }
        }
        public void UpdateLocalizedSettings(object settings, FormCollection form, int storeId, ISettingService settingService, ILocalizedModelLocal localized)
        {
            var settingName = settings.GetType().Name;
            var properties = localized.GetType().GetProperties();

            foreach (var prop in properties)
            {
                var name = prop.Name;
                var key = settingName + "." + name;

                if (storeId == 0 || IsOverrideChecked(key, form))
                {
                    dynamic value = settings.TryGetPropertyValue(name);
                    settingService.SetSetting(key, value == null ? "" : value, storeId, false);
                }
                else if (storeId > 0)
                {
                    settingService.DeleteSetting(key, storeId);
                }
            }
        }
        public void GetOverrideKeysLocalized(object settings, object model, int storeId, ISettingService settingService, bool isRootModel = true, ILocalizedModelLocal localized = null, int? index = null)
        {
            if (storeId <= 0)
                return;		// single store mode -> there are no overrides

            var data = Data;
            if (data == null)
                data = new StoreDependingSettingData();

            var settingName = settings.GetType().Name;
            var properties = localized.GetType().GetProperties();

            var modelType = model.GetType();

            foreach (var prop in properties)
            {
                var name = prop.Name;
                var modelProperty = modelType.GetProperty(name);

                if (modelProperty == null)
                    continue;	// setting is not configurable or missing or whatever... however we don't need the override info

                var key = "Locales[" + index.ToString() + "]." + name;

                var leService = EngineContext.Current.Resolve<ILocalizedEntityService>();
                var resultStr = leService.GetLocalizedValue(localized.LanguageId, 0, settingName, name);

                if (!String.IsNullOrEmpty(resultStr))
                    data.OverrideSettingKeys.Add(key);
            }

            if (isRootModel)
            {
                data.ActiveStoreScopeConfiguration = storeId;
                data.RootSettingClass = settingName;

                _viewData[ViewDataKey] = data;
            }
        }