Пример #1
0
        /// <summary>
        /// 保存系统参数配置
        /// </summary>
        /// <param name="type"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        public bool SaveSetting(SystemSetting.SettingType type, string value)
        {
            using (DbExecutor db = NewExecutor(IsolationLevel.ReadUncommitted))
            {
                SystemSetting setting = new SystemSetting()
                {
                    Type  = type,
                    Value = value
                };
                if (setting.Exists(db))
                {
                    setting.Update(db);
                }
                else
                {
                    setting.Add(db);
                }

                db.AddCallback(() =>
                {
                    SystemCaching.Instance().SaveSetting(type, value);
                });

                db.Commit();
            }
            return(true);
        }
Пример #2
0
        /// <summary>
        /// 获取系统的参数配置(Redis中读取,不存在则从数据库读取)
        /// </summary>
        /// <param name="type"></param>
        /// <returns></returns>
        protected string GetSetting(SystemSetting.SettingType type)
        {
            string value = SystemCaching.Instance().GetSetting(type);

            if (string.IsNullOrEmpty(value))
            {
                value = this.ReadDB.ExecuteScalar <SystemSetting, string>(t => t.Value, t => t.Type == type);
                if (!string.IsNullOrEmpty(value))
                {
                    SystemCaching.Instance().SaveSetting(type, value);
                }
            }
            return(value);
        }