public Schedule Add(bool mon, bool tue, bool wed, bool thu, bool fri, bool sat, bool sun, int deviceID, DateTime time, short temperture, short fan, Mode mode)
        {
            int id = 0;

            using (var context = new HomeAutomationContext())
            {
                if (context.Schedules.Count() > 0)

                {
                    id = context.Schedules.Max(o => o.ID) + 1;
                }

                var schedule = new Schedule()
                {
                    ID          = id,
                    Mon         = mon,
                    Tue         = tue,
                    Wed         = wed,
                    Thu         = thu,
                    Fri         = fri,
                    Sun         = sun,
                    Sat         = sat,
                    DeviceID    = deviceID,
                    Time        = time,
                    Mode        = mode,
                    Fan         = fan,
                    Temperature = temperture
                };

                context.Schedules.Add(schedule);
                context.SaveChanges();
                return(schedule);
            }
        }
 public void Delete(int ID)
 {
     using (var context = new HomeAutomationContext())
     {
         context.Remove(context.Devices.Where(o => o.ID == ID).FirstOrDefault());
         context.SaveChanges();
     }
 }
 public void Delete(int iD)
 {
     using (var context = new HomeAutomationContext())
     {
         var r = context.Schedules.Where(o => o.ID == iD).FirstOrDefault();
         context.Schedules.Remove(r);
         context.SaveChanges();
     }
 }
        public void UpdateTemperature(int ID, float?temperature)
        {
            using (var context = new HomeAutomationContext())
            {
                var item = context.Devices.Where(o => o.ID == ID).FirstOrDefault();

                item.Temperature = temperature;
                context.SaveChanges();
            }
        }
        public void Update(Device device)
        {
            using (var context = new HomeAutomationContext())
            {
                var item = context.Devices.Where(o => o.ID == device.ID).FirstOrDefault();

                item.Appliance   = device.Appliance;
                item.Name        = device.Name;
                item.NodeAddress = device.NodeAddress;
                context.SaveChanges();
            }
        }
 public Device Add(string nodeAddress, string name, Appliance appliance)
 {
     using (var context = new HomeAutomationContext())
     {
         int id     = context.Devices.Max(o => o.ID) + 1;
         var device = new Device()
         {
             ID = id, NodeAddress = nodeAddress, Name = name, Appliance = appliance
         };
         context.Devices.Add(device);
         context.SaveChanges();
         return(device);
     }
 }