예제 #1
0
        public bool GetSetting(SettingLookupInfo lookupInfo, out object value, DataAccessSession dataSession, bool lookForDefault = false)
        {
            SettingModel settingModel = GetSettingInfo(lookupInfo.SettingName);
            string       sql          = Queries.getSetting;
            string       stringValue  = dataSession.LoadData <string, SettingLookupInfo>(sql, lookupInfo).FirstOrDefault();

            if (stringValue is null)
            {
                if (!lookForDefault)
                {
                    value = default;
                    return(false);
                }
                if (lookupInfo.UId.HasValue && lookupInfo.GId.HasValue && !lookupInfo.CId.HasValue)
                {
                    lookupInfo.GId = null;
                    return(GetSetting(lookupInfo, out value, lookForDefault));
                }
                if (!lookupInfo.UId.HasValue && lookupInfo.GId.HasValue && lookupInfo.CId.HasValue)
                {
                    lookupInfo.CId = null;
                    return(GetSetting(lookupInfo, out value, lookForDefault));
                }
                value = settingModel.DefaultValue;
                return(true);
            }
            value = settingModel.Convert(stringValue);
            return(true);
        }
예제 #2
0
        public void SetSetting(SettingLookupInfo lookupInfo, object value, DataAccessSession dataSession = null)
        {
            string       sql;
            SettingModel settingModel = GetSettingInfo(lookupInfo.SettingName);

            if (value is null)
            {
                sql = Queries.removeSetting;
                Data.SaveData(sql, lookupInfo);
                return;
            }
            sql = Queries.updateSetting;
            string stringValue = settingModel.Convert(value);
            var    parameters  = new { lookupInfo.SettingName, lookupInfo.Ids, Value = stringValue };

            Data.SaveData(sql, parameters);
        }