public static void ToggleRoom(int roomId, int action) { try { using (var dbContext = new AutoLuminosityDataDataContext()) { string lightAction = string.Empty; if (action == 1) { lightAction = "on"; } else if (action == 2) { lightAction = "off"; } string jsonRequest = "{ \"power\": \"" + lightAction + "\" }"; var room = dbContext.AutoLuminosity_Rooms.FirstOrDefault(i => i.RoomId == roomId); if (room != null) { LifxConnector.ToggleRoom(room.RoomExternalId, jsonRequest); } } } catch (Exception ex) { } }
public static void ExecuteSchedule(int scheduleId) { try { using (var dbContext = new AutoLuminosityDataDataContext()) { var schedule = dbContext.AutoLuminosity_Schedules.FirstOrDefault(i => i.ScheduleId == scheduleId); if (schedule != null) { string action = string.Empty; if (schedule.ScheduleAction == 1) { action = "on"; } else if (schedule.ScheduleAction == 2) { action = "off"; } string jsonRequest = "{ \"power\": \"" + action + "\" }"; if (schedule.ScheduleType == ScheduleType.Light) { var light = dbContext.AutoLuminosity_Lights.FirstOrDefault(i => i.LightId == schedule.ScheduleEntityId); if (light != null) { LifxConnector.ToggleLight(light.LightExternalId, jsonRequest); } } else if (schedule.ScheduleType == ScheduleType.Room) { var room = dbContext.AutoLuminosity_Rooms.FirstOrDefault(i => i.RoomId == schedule.ScheduleEntityId); if (room != null) { LifxConnector.ToggleRoom(room.RoomExternalId, jsonRequest); } } } } } catch (Exception ex) { } }
public static void ToggleRoom(int roomId) { try { using (var dbContext = new AutoLuminosityDataDataContext()) { string lightAction = "on"; bool turnLightsOn = true; var roomLightLinks = dbContext.AutoLuminosity_RoomLightLinks.Where(i => i.RoomId == roomId); roomLightLinks.ToList().ForEach(l => { var light = dbContext.AutoLuminosity_Lights.FirstOrDefault(i => l.LightId == i.LightId); if (light.LightIsOn) { turnLightsOn = false; lightAction = "off"; } }); roomLightLinks.ToList().ForEach(l => { var light = dbContext.AutoLuminosity_Lights.FirstOrDefault(i => l.LightId == i.LightId); light.LightIsOn = turnLightsOn; }); dbContext.SubmitChanges(); string jsonRequest = "{ \"power\": \"" + lightAction + "\" }"; var room = dbContext.AutoLuminosity_Rooms.FirstOrDefault(i => i.RoomId == roomId); if (room != null) { LifxConnector.ToggleRoom(room.RoomExternalId, jsonRequest); } } } catch (Exception ex) { } }