Ejemplo n.º 1
0
            /// <summary>
            /// Sets a site setting in the database.  All values are strings.
            /// </summary>
            /// <param name="setting">The setting to set. Use pre-defined constants in SiteSettings class.</param>
            /// <param name="value">The value to store in the database.</param>
            /// <returns>The value of the setting, or null</returns>
            public static void SetValue(String setting, String value)
            {
                UnitOfWork work = new UnitOfWork();

                system_setting ss = (from s in work.EntityContext.system_setting
                                     where s.key == setting
                                     select s).FirstOrDefault();

                // Making a new one, or updating?
                if (ss == null)
                {
                    // Make a new one and add it
                    ss = new system_setting()
                    {
                        key      = setting,
                        key_hash = 0,                           // Unused for now
                        value    = value
                    };
                    work.EntityContext.system_setting.Add(ss);
                }
                else
                {
                    ss.value = value;
                }

                work.SaveChanges();
            }
Ejemplo n.º 2
0
            /// <summary>
            /// Gets a setting's value from the database.  All values are string.
            /// Returns a default value if the setting doesn't exist in the database, or null if neither exist.
            /// </summary>
            /// <param name="setting">The setting to get. Use pre-defined constants in SiteSettings class.</param>
            /// <returns>The value of the setting, or null</returns>
            public static String GetValue(String setting)
            {
                UnitOfWork work = new UnitOfWork();

                system_setting ss = (from s in work.EntityContext.system_setting
                                     where s.key == setting
                                     select s).FirstOrDefault();

                if (ss == null)
                {
                    // Return default
                    // TODO: Log default return?
                    return(DefaultValues[setting]);
                }

                // Return the actual stored value
                return(ss.value);
            }