/// <summary>
        /// 获取该用户所有软情景
        /// </summary>
        /// <param name="openId">用户微信的唯一值</param>
        /// <returns></returns>
        public JsonResult GetAllUserScene(string openId)
        {
            //通过用户选择的网关Id进行该网关下情景的查询
            var sql = "SELECT * FROM iot_scene WHERE GateWayID IN ( " +
                      "SELECT GateWayID FROM iot_user_gateway WHERE UserId = (" +
                      $"SELECT Id FROM iot_user WHERE OpenId = '{openId}'))";
            var temp = db.Database.SqlQuery <iot_scene>(sql).ToList();


            if (temp == null)
            {
                return(Json(new { status = StatusCode.NotFound, message = "未找到软情景信息" }));
            }

            List <iot_scene> list = new List <iot_scene>();

            //将得到的数据使用result保存起来
            foreach (var item in temp)
            {
                var result = new iot_scene
                {
                    ID         = item.ID,
                    GateWayId  = item.GateWayId,
                    Name       = item.Name,
                    CreateTime = item.CreateTime,
                    ActionType = item.ActionType,
                    EditTime   = item.EditTime
                };
                list.Add(result);
            }

            return(Json(list, JsonRequestBehavior.AllowGet));
        }
        public JsonResult AddScene([System.Web.Http.FromBody] iot_scene model)
        {
            iot_scene scene = new iot_scene
            {
                Name = model.Name,

                GateWayId  = model.GateWayId,
                ActionType = util.SetActionType(model.GateWayId),

                CreateTime = new DateTime(),
                EditTime   = null
            };

            db.iot_scene.Add(scene);

            var taskinfo = new { status = StatusCode.SUCCESS, message = "添加成功" };
            int uprows   = db.SaveChanges();

            if (uprows < 1)
            {
                taskinfo = new { status = StatusCode.FAIL, message = "添加失败" };
            }

            return(Json(taskinfo, JsonRequestBehavior.AllowGet));
        }
        /// <summary>
        /// 修改软情景的名字
        /// </summary>
        /// <param name="sceneId"></param>
        /// <param name="name"></param>
        /// <returns></returns>
        public JsonResult EditScene(int sceneId, string name)
        {
            iot_scene scene = db.iot_scene.Find(sceneId);

            scene.Name = name;

            var taskinfo = new { status = StatusCode.SUCCESS, message = "修改成功" };
            int uprows   = db.SaveChanges();

            if (uprows < 1)
            {
                taskinfo = new { status = StatusCode.FAIL, message = "修改失败" };
            }

            return(Json(taskinfo, JsonRequestBehavior.AllowGet));
        }
        /// <summary>
        /// 删除一个软情景
        /// </summary>
        /// <param name="id">该软情景的唯一标识</param>
        /// <returns></returns>
        public JsonResult DelScene(int id)
        {
            iot_scene scene = db.iot_scene.Find(id);

            db.iot_scene.Remove(scene);

            var taskinfo = new { status = StatusCode.SUCCESS, message = "删除成功" };
            int uprows   = db.SaveChanges();

            if (uprows < 1)
            {
                taskinfo = new { status = StatusCode.FAIL, message = "删除失败" };
            }

            return(Json(taskinfo, JsonRequestBehavior.AllowGet));
        }