private void OnOffDevice(int id, string type, int roomId) { using (SmartHouseContext context = new SmartHouseContext()) { if (context.Alarms.Any()) { if (type == context.Alarms.FirstOrDefault().GetType().ToString()) { Alarm device = context.Alarms.Find(id); device.OnOff(); device.Room = context.Rooms.Find(roomId); context.SaveChanges(); return; } else { } } else { } if (context.Conditioners.Any()) { if (type == context.Conditioners.FirstOrDefault().GetType().ToString()) { Conditioner device = context.Conditioners.Find(id); device.OnOff(); device.Room = context.Rooms.Find(roomId); context.SaveChanges(); return; } else { } } else { } if (context.Exhausters.Any()) { if (type == context.Exhausters.FirstOrDefault().GetType().ToString()) { Exhauster device = context.Exhausters.Find(id); device.OnOff(); device.Room = context.Rooms.Find(roomId); context.SaveChanges(); return; } else { } } else { } if (context.Fridges.Any()) { if (type == context.Fridges.FirstOrDefault().GetType().ToString()) { Fridge device = context.Fridges.Find(id); device.OnOff(); device.Room = context.Rooms.Find(roomId); context.SaveChanges(); return; } else { } } else { } if (context.Jalousies.Any()) { if (type == context.Jalousies.FirstOrDefault().GetType().ToString()) { Jalousie device = context.Jalousies.Find(id); device.OnOff(); device.Room = context.Rooms.Find(roomId); context.SaveChanges(); return; } else { } } else { } if (context.Lamps.Any()) { if (type == context.Lamps.FirstOrDefault().GetType().ToString()) { Lamp device = context.Lamps.Find(id); device.OnOff(); device.Room = context.Rooms.Find(roomId); context.SaveChanges(); return; } else { } } else { } if (context.Radiators.Any()) { if (type == context.Radiators.FirstOrDefault().GetType().ToString()) { Radiator device = context.Radiators.Find(id); device.OnOff(); device.Room = context.Rooms.Find(roomId); context.SaveChanges(); return; } else { } } else { } if (context.Routers.Any()) { if (type == context.Routers.FirstOrDefault().GetType().ToString()) { Router device = context.Routers.Find(id); device.OnOff(); device.Room = context.Rooms.Find(roomId); context.SaveChanges(); return; } else { } } else { } if (context.StereoSystems.Any()) { if (type == context.StereoSystems.FirstOrDefault().GetType().ToString()) { StereoSystem device = context.StereoSystems.Find(id); device.OnOff(); device.Room = context.Rooms.Find(roomId); context.SaveChanges(); return; } else { } } else { } if (context.TVs.Any()) { if (type == context.TVs.FirstOrDefault().GetType().ToString()) { TV device = context.TVs.Find(id); device.OnOff(); device.Room = context.Rooms.Find(roomId); context.SaveChanges(); return; } else { } } else { } } return; }