public async Task <IActionResult> Index(int id, [Bind("DoorOpenHabLink,GateOpenHabLink,StatusOpenHabLink,GateTimeout,AutoGateTimeout,MaxErrorLogRows")] Settings settings) { Settings currentSettings = _context.Settings.First(); if (currentSettings == null) { return(NotFound()); } if (ModelState.IsValid) { try { currentSettings.DoorOpenHabLink = settings.DoorOpenHabLink; currentSettings.GateOpenHabLink = settings.GateOpenHabLink; currentSettings.StatusOpenHabLink = settings.StatusOpenHabLink; currentSettings.GateTimeout = settings.GateTimeout; currentSettings.AutoGateTimeout = settings.AutoGateTimeout; currentSettings.MaxErrorLogRows = settings.MaxErrorLogRows; _context.Update(currentSettings); await _context.SaveChangesAsync(); _iDataSingleton.SetSettings(currentSettings); } catch (DbUpdateConcurrencyException) { return(NotFound()); } return(RedirectToAction(nameof(Index))); } return(View(settings)); }
public ScopedService(IOpenHabMessageService openHab, IDataSingleton dataSingleton, UserDbContext context) { _openHab = openHab; _dataSingleton = dataSingleton; _context = context; Settings settings = _context.Settings.First(); _dataSingleton.SetSettings(settings); }