示例#1
0
        public string RegDevice(RegDeviceRequest model)
        {
            var rst = new ReturnResult <RegDeviceResult>();

            var api    = new DeviceApi();
            var apiRst = api.RegDevice(model);

            if (apiRst.Result && !string.IsNullOrEmpty(apiRst.Data.deviceId))
            {
                //根据设备型号查找profile
                var bll        = new ProfileBll();
                var profileRst = bll.GetOneByModel(new Profile()
                {
                    Model = model.model
                });
                if (profileRst.Result)
                {
                    var profile = profileRst.Data;
                    //修改设备
                    var updateRst = api.UpdateDevice(model.appId, apiRst.Data.deviceId, model.name, profile, "CoAP");
                    if (updateRst.Result && updateRst.Status == "NoContent")
                    {
                        rst.Result  = true;
                        rst.Data    = apiRst.Data;
                        rst.Message = "注册成功";
                    }
                    else
                    {
                        rst.Message = "注册失败";
                    }
                }
                else
                {
                    rst.Message = "设备型号不存在";
                }
                //插入用户设备表
                var device = new UserDevice()
                {
                    DeviceId   = apiRst.Data.deviceId,
                    DeviceName = model.name,
                    VerifyCode = model.verifyCode,
                    NodeId     = model.nodeId,
                    ProfileId  = profileRst.Data?.Id,
                    UserId     = model.userId
                };
                var addDeviceRst = new UserDeviceBll().AddOrUpdate(device);
                if (addDeviceRst.Result)
                {
                    rst.Result  = true;
                    rst.Message = "注册成功";
                }
            }
            else
            {
                rst.Message = "注册失败";
            }

            return(JsonHelper.Instance.Serialize(rst));
        }
示例#2
0
        public string Del(Profile model)
        {
            var rst = new ReturnResult <bool>();
            var bll = new ProfileBll();

            rst = bll.Delete(model);

            return(JsonHelper.Instance.Serialize(rst));
        }
示例#3
0
        public string GetList(Profile model)
        {
            var rst = new ReturnResult <List <Profile> >();
            var bll = new ProfileBll();

            rst = bll.GetList(model);

            return(JsonHelper.Instance.Serialize(rst));
        }
示例#4
0
        public string Add(Profile model)
        {
            var rst = new ReturnResult <bool>();
            var bll = new ProfileBll();

            if (model.Id == 0)
            {
                rst = bll.Add(model);
            }
            else
            {
                rst = bll.Update(model);
            }

            return(JsonHelper.Instance.Serialize(rst));
        }