Exemplo n.º 1
0
        /// <summary>
        /// 提交用户设备绑定,解绑
        /// </summary>
        /// <param name="imei"></param>
        /// <param name="type"></param>
        /// <param name="loginName"></param>
        /// <returns></returns>
        public JsonResult AjaxSubUD(string imei, int type, string loginName)
        {
            BaseResult res = new BaseResult();

            //解绑
            if (type == 1)
            {
                Device d = DeviceLogic.GetDeviceByImei(imei);
                if (d == null)
                {
                    res.State   = State.NotFind;
                    res.Message = "该设备不存在!";
                    return(Json(res));
                }
                User user = UserLogic.GetUserById(d.UserId);
                if (user != null)
                {
                    BaseModel bm = DeviceData.UnBind(d.Imei);
                    if (bm.State == 0)
                    {
                        d.UserId = 0;
                        DeviceLogic.SaveDevice(d);
                        SaveUserLog(AuthUser.LoginName + "将设备:" + d.Imei + ",从用户" + user.LoginName + "中解绑了。", LogLevel.Sensitive, AuthUser.LoginName, "AjaxSubUD", "解绑设备");
                        res.State   = State.Success;
                        res.Message = "解绑成功!";
                    }
                    else
                    {
                        res.State   = State.Falid;
                        res.Message = "解绑失败:" + bm.Message;
                    }
                }
            }
            //绑定
            else if (type == 2)
            {
                User user = UserLogic.GetUser(loginName);

                if (user == null)
                {
                    res.State   = State.NotFind;
                    res.Message = "用户不存在!";
                    return(Json(res));
                }
                user.IMEI = imei;
                //准备绑定设备
                Device d = preBindDevice(user);
                if (d != null)
                {
                    BaseModel bm = DeviceData.BindDevice(d.APIDeviceId.Value, user.APIUserId.Value);
                    if (bm.State != 0)
                    {
                        res.State   = State.Falid;
                        res.Message = "绑定失败:" + bm.Message;
                        return(Json(res));
                    }
                    d.UserId = user.Id;
                    DeviceLogic.SaveDevice(d);
                    SaveUserLog(AuthUser.LoginName + "将设备:" + d.Imei + "绑定到了用户" + loginName, LogLevel.Sensitive, AuthUser.LoginName, "AjaxSubUD", "删除设备");
                    res.State   = 0;
                    res.Message = "绑定成功!";
                }
                else
                {
                    res.State   = State.Falid;
                    res.Message = "设备验证失败";
                }
            }
            else if (type == 3)
            {
                if (AuthUser.UserTypeId == 2 || AuthUser.UserTypeId == 1)
                {
                    Device _d = DeviceLogic.GetDeviceByImei(imei);
                    DeviceLogic.DelDevice(_d.Id);
                    res.State   = State.Success;
                    res.Message = "删除设备成功!";
                    SaveUserLog(AuthUser.LoginName + "删除了设备:" + imei, LogLevel.Sensitive, AuthUser.LoginName, "AjaxSubUD", "删除设备");
                }
                else
                {
                    res.State   = State.Falid;
                    res.Message = "暂无删除设备的权限";
                    SaveUserLog(AuthUser.LoginName + "删除设备失败:" + imei, LogLevel.Sensitive, AuthUser.LoginName, "AjaxSubUD", "删除设备");
                }
            }
            return(Json(res));
        }