public async Task IterateScenarios() { var deviceController = new DeviceController(_context); DateTime currentTime = DateTime.Now; List <Models.Scenario> scenarios = _context.Scenarios.ToList(); foreach (var scenario in scenarios) { if (DateTime.Compare(scenario.TimeOfEvent, DateTime.Now) < 0) { await deviceController.ExecuteScene(scenario.Id); } } }