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"; } }
public ActionResult TconstSet(Sensor model) { using (var context = new DevicesEntities()) { var device = (from entity in context.Sensor where entity.DeviceSerial == model.DeviceSerial select entity).First(); device.tconst = model.tconst; UpdateModel(device); context.SaveChanges(); TcpClient Client = new TcpClient(); Client.Connect(IPAddress.Parse(IpPort.ip), IpPort.port); Socket Sock = Client.Client; Sock.Send(MySerialize.serialize(device, typeof(Sensor))); Sock.Close(); Client.Close(); } return RedirectToAction("Index", "Home"); }