Esempio n. 1
0
        /// <summary>
        /// 保存网站配置实例。
        /// </summary>
        /// <param name="key">配置唯一键。</param>
        /// <param name="settings">网站配置实例。</param>
        public bool SaveSettings(string key, string settings)
        {
            var cacheKey = GetCacheKey(key, out var siteId);
            var adapter  = new SettingsAdapter {
                SettingKey = key, SettingValue = settings, SiteId = siteId
            };

            if (_db.Any(x => x.SettingKey == key && x.SiteId == siteId))
            {
                if (_db.Update(adapter))
                {
                    _cache.Remove(cacheKey);
                    return(true);
                }
            }
            return(_db.Create(adapter));
        }
Esempio n. 2
0
        /// <summary>
        /// 保存网站配置实例。
        /// </summary>
        /// <param name="key">配置唯一键。</param>
        /// <param name="settings">网站配置实例。</param>
        public virtual async Task <bool> SaveSettingsAsync(string key, string settings)
        {
            var cacheKey = GetCacheKey(key, out var siteId);
            var adapter  = new SettingsAdapter {
                SettingKey = key, SettingValue = settings, SiteId = siteId
            };

            if (await _db.AnyAsync(x => x.SettingKey == key && x.SiteId == siteId))
            {
                if (await _db.UpdateAsync(adapter))
                {
                    _cache.Remove(cacheKey);
                    return(true);
                }
            }
            return(await _db.CreateAsync(adapter));
        }