예제 #1
0
        public string AddSensor(int DeviceSerial, int Type, int State, int Tconst, int Temp)
        {
            using (var context = new DevicesEntities())
            {

                Device device = new Device();
                device.DeviceSerial = DeviceSerial;
                device.Type = Type;
                device.State = State;
                device.UserName = "******";

                Sensor sensor = new Sensor();
                sensor.DeviceSerial = DeviceSerial;
                sensor.tconst = Tconst;
                sensor.temperature = Temp;
                try
                {
                    context.Device.Add(device);
                    context.Sensor.Add(sensor);
                    context.SaveChanges();
                }
                catch (Exception ex)
                {
                    return ex.Message;
                }

                return "Sensor" + device.DeviceSerial + "Connected";

            }
        }
예제 #2
0
        public string AddDevice(int DeviceSerial, int Type, int State)
        {
            using (var context = new DevicesEntities())
            {

                Device device = new Device();
                device.DeviceSerial = DeviceSerial;
                device.Type = Type;
                device.State = State;
                device.UserName = "******";
                try
                {
                    context.Device.Add(device);
                    context.SaveChanges();
                }
                catch (Exception ex)
                {
                    return ex.Message;
                }

                return "Device" + device.DeviceSerial + "Connected";

            }
        }