Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
public class DbConfigurationService : ConfigurationService
{
    protected override bool ValueExists(string key)
    {
        using (var context = new ConfigurationContext())
        {
            return (from config in context.Configurations
                    where config.Key == key
                    select config).Any();
        }
    }
 
    protected override string GetValueFromStore(string key)
    {
        using (var context = new ConfigurationContext())
        {
            return (from config in context.Configurations
                    where config.Key == key
                    select config.Value).First();
        }
    }

    protected override void SetValueToStore(string key, string value)
    {
        using (var context = new ConfigurationContext())
        {
            var configuration (from config in context.Configurations
                    where config.Key == key
                    select config).FirstOrDefault();

            if (configuration == null)
            {
                configuration = context.CreateObject<Configuration>();
                configuration.Key = key;
            }

            configuration.Value = value;
            context.SaveChanges();
        }
    }
}

...