Ejemplo n.º 1
0
 private void RenameDevice(int id, string type, string name)
 {
     using (SmartHouseContext context = new SmartHouseContext())
     {
         if (context.Alarms.Any())
         {
             if (type == context.Alarms.FirstOrDefault().GetType().ToString())
             {
                 Alarm device = context.Alarms.Find(id);
                 device.Name = name;
                 device.Room = context.Rooms.Find(Session["CurrentRoom"]);
                 context.SaveChanges();
                 return;
             }
             else
             {
             }
         }
         else
         {
         }
         if (context.Conditioners.Any())
         {
             if (type == context.Conditioners.FirstOrDefault().GetType().ToString())
             {
                 Conditioner device = context.Conditioners.Find(id);
                 device.Name = name;
                 device.Room = context.Rooms.Find(Session["CurrentRoom"]);
                 context.SaveChanges();
                 return;
             }
             else
             {
             }
         }
         else
         {
         }
         if (context.Exhausters.Any())
         {
             if (type == context.Exhausters.FirstOrDefault().GetType().ToString())
             {
                 Exhauster device = context.Exhausters.Find(id);
                 device.Name = name;
                 device.Room = context.Rooms.Find(Session["CurrentRoom"]);
                 context.SaveChanges();
                 return;
             }
             else
             {
             }
         }
         else
         {
         }
         if (context.Fridges.Any())
         {
             if (type == context.Fridges.FirstOrDefault().GetType().ToString())
             {
                 Fridge device = context.Fridges.Find(id);
                 device.Name = name;
                 device.Room = context.Rooms.Find(Session["CurrentRoom"]);
                 context.SaveChanges();
                 return;
             }
             else
             {
             }
         }
         else
         {
         }
         if (context.Jalousies.Any())
         {
             if (type == context.Jalousies.FirstOrDefault().GetType().ToString())
             {
                 Jalousie device = context.Jalousies.Find(id);
                 device.Name = name;
                 device.Room = context.Rooms.Find(Session["CurrentRoom"]);
                 context.SaveChanges();
                 return;
             }
             else
             {
             }
         }
         else
         {
         }
         if (context.Lamps.Any())
         {
             if (type == context.Lamps.FirstOrDefault().GetType().ToString())
             {
                 Lamp device = context.Lamps.Find(id);
                 device.Name = name;
                 device.Room = context.Rooms.Find(Session["CurrentRoom"]);
                 context.SaveChanges();
                 return;
             }
             else
             {
             }
         }
         else
         {
         }
         if (context.Radiators.Any())
         {
             if (type == context.Radiators.FirstOrDefault().GetType().ToString())
             {
                 Radiator device = context.Radiators.Find(id);
                 device.Name = name;
                 device.Room = context.Rooms.Find(Session["CurrentRoom"]);
                 context.SaveChanges();
                 return;
             }
             else
             {
             }
         }
         else
         {
         }
         if (context.Routers.Any())
         {
             if (type == context.Routers.FirstOrDefault().GetType().ToString())
             {
                 Router device = context.Routers.Find(id);
                 device.Name = name;
                 device.Room = context.Rooms.Find(Session["CurrentRoom"]);
                 context.SaveChanges();
                 return;
             }
             else
             {
             }
         }
         else
         {
         }
         if (context.StereoSystems.Any())
         {
             if (type == context.StereoSystems.FirstOrDefault().GetType().ToString())
             {
                 StereoSystem device = context.StereoSystems.Find(id);
                 device.Name = name;
                 device.Room = context.Rooms.Find(Session["CurrentRoom"]);
                 context.SaveChanges();
                 return;
             }
             else
             {
             }
         }
         else
         {
         }
         if (context.TVs.Any())
         {
             if (type == context.TVs.FirstOrDefault().GetType().ToString())
             {
                 TV device = context.TVs.Find(id);
                 device.Name = name;
                 device.Room = context.Rooms.Find(Session["CurrentRoom"]);
                 context.SaveChanges();
                 return;
             }
             else
             {
             }
         }
         else
         {
         }
     }
     return;
 }
Ejemplo n.º 2
0
        private void CreateNewDevice(string type, string lampType, string name)
        {
            using (SmartHouseContext context = new SmartHouseContext())
            {
                int id = (int)Session["CurrentRoom"];
                switch (type)
                {
                case "Alarm":
                    Alarm newAlarm = new Alarm(name);
                    context.Rooms.FirstOrDefault(d => d.Id == id).Alarm.Add(newAlarm);
                    break;

                case "Conditioner":
                    Conditioner newConditioner = new Conditioner(name);
                    context.Rooms.FirstOrDefault(d => d.Id == id).Conditioner.Add(newConditioner);
                    break;

                case "Exhauster":
                    Exhauster newExhauster = new Exhauster(name);
                    context.Rooms.FirstOrDefault(d => d.Id == id).Exhauster.Add(newExhauster);
                    break;

                case "Fridge":
                    Fridge newFridge = new Fridge(name);
                    context.Rooms.FirstOrDefault(d => d.Id == id).Fridge.Add(newFridge);
                    break;

                case "Jalousie":
                    Jalousie newJalousie = new Jalousie(name);
                    context.Rooms.FirstOrDefault(d => d.Id == id).Jalousie.Add(newJalousie);
                    break;

                case "Lamp":
                    Lamp newLamp = new Lamp(name, lampType);
                    context.Rooms.FirstOrDefault(d => d.Id == id).Lamp.Add(newLamp);
                    break;

                case "Radiator":
                    Radiator newRadiator = new Radiator(name);
                    context.Rooms.FirstOrDefault(d => d.Id == id).Radiator.Add(newRadiator);
                    break;

                case "Router":
                    Router newRouter = new Router(name);
                    context.Rooms.FirstOrDefault(d => d.Id == id).Router.Add(newRouter);
                    break;

                case "StereoSystem":
                    StereoSystem newStereoSystem = new StereoSystem(name);
                    context.Rooms.FirstOrDefault(d => d.Id == id).StereoSystem.Add(newStereoSystem);
                    break;

                case "TV":
                    TV newTV = new TV(name);
                    context.Rooms.FirstOrDefault(d => d.Id == id).TV.Add(newTV);
                    break;

                default:
                    Alarm newAlarma = new Alarm(name);
                    context.Rooms.FirstOrDefault(d => d.Id == id).Alarm.Add(newAlarma);
                    break;
                }
                context.SaveChanges();
            }
        }