/// <summary> /// Initializes thermostat default values from appsettings.json /// if they don't exist in DB /// </summary> public void Init() { var connectionString = _appSettings.GetConnectionString("MomitKiller"); using (var db = new MomitKillerDbContext(connectionString)) { _thermostatConfig = db.ThermostatConfig.FirstOrDefault(); if (_thermostatConfig == null) { var thermostatDefaults = _appSettings .GetSection("ThermostatDefaults"); _thermostatConfig = new ThermostatConfig() { Id = 1, Setpoint = thermostatDefaults .GetValue <decimal>("Temperature"), Hysteresis = thermostatDefaults .GetValue <decimal>("Hysteresis"), Calibration = thermostatDefaults .GetValue <decimal>("Calibration"), Mode = thermostatDefaults .GetValue <ThermostatModes>("Mode") }; db.ThermostatConfig.Add(_thermostatConfig); db.SaveChanges(); } } }
/// <summary> /// Initializes thermostat default values from appsettings.json /// if they don't exist in DB /// </summary> public void Init() { var connectionString = _appConfig.GetConnectionString("MomitKiller"); using (var db = new MomitKillerDbContext(connectionString)) { _configuration = db.Configuration.FirstOrDefault(); if (_configuration == null) { var thermostatDefaults = _appConfig .GetSection("ThermostatDefaults"); _configuration = new Configuration() { Id = 1, Temperature = thermostatDefaults .GetValue <float>("Temperature"), Hysteresis = thermostatDefaults .GetValue <float>("Hysteresis") }; db.Configuration.Add(_configuration); db.SaveChanges(); } } }