Example #1
0
        public Preference Set(string key, object value, bool isPublic)
        {
            if (!BaseSecurity.IsSysAdmin(Context))
            {
                throw new ChalkableSecurityException(ChlkResources.ERR_PREFERENCE_INVALID_RIGHTS);
            }

            using (var uow = Update())
            {
                var da         = new PreferenceDataAccess(uow);
                var preference = da.GetPreferenceOrNull(key);
                if (preference == null)
                {
                    preference = CreatePreference(isPublic, key, new PreferenceInfo
                    {
                        Category = cache[key].Category,
                        Type     = cache[key].Type,
                        Value    = value.ToString(),
                        Hint     = cache[key].Hint
                    });
                    da.Insert(preference);
                }
                else
                {
                    preference.Value    = value.ToString();
                    preference.IsPublic = isPublic;
                    da.Update(preference);
                }
                cache[key] = preference;
                uow.Commit();
                return(preference);
            }
        }
Example #2
0
 private void SetPreferences(IList <Preference> preferences)
 {
     using (var uow = Update())
     {
         var da        = new PreferenceDataAccess(uow);
         var forInsert = preferences.Where(p => !cache.ContainsKey(p.Key)).ToList();
         da.Insert(forInsert);
         foreach (var p in forInsert)
         {
             cache.Add(p.Key, p);
         }
         uow.Commit();
     }
 }