Exemplo n.º 1
0
        // create a new group
        public JsonResult ModifyGroup(string user, string id, [FromBody] ModifyGroupRequest modifiedGroup)
        {
            // authentication
            if (!_grp.AuthenticatorInstance.IsValidUser(user))
            {
                return(Json(_grp.AuthenticatorInstance.ErrorResponse(Request.Path.ToString())));
            }

            var groups = _grp.DatabaseInstance.GetCollection <Group>("groups");
            var group  = groups.FindById(Convert.ToInt64(id));

            if (group == null)
            {
                return(Json(new
                {
                    failure = $"group {id} not found"
                }));
            }

            group.Name   = modifiedGroup.Name ?? group.Name;
            group.Class  = modifiedGroup.Class ?? group.Class;
            group.Lights = modifiedGroup.Lights ?? group.Lights;

            groups.Update(group);

            var ret = new List <Dictionary <string, object> >
            {
                new Dictionary <string, object>
                {
                    ["success"] = new Dictionary <string, object>
                    {
                        [$"/groups/{id}/name"] = group.Name
                    }
                },
                new Dictionary <string, object>
                {
                    ["success"] = new Dictionary <string, object>
                    {
                        [$"/groups/{id}/class"] = group.Class
                    }
                },
                new Dictionary <string, object>
                {
                    ["success"] = new Dictionary <string, object>
                    {
                        [$"/groups/{id}/lights"] = group.Lights
                    }
                }
            };

            return(Json(ret));
        }
        /// <summary>
        /// 修改人体库名称、备注。
        /// </summary>
        /// <param name="req"><see cref="ModifyGroupRequest"/></param>
        /// <returns><see cref="ModifyGroupResponse"/></returns>
        public ModifyGroupResponse ModifyGroupSync(ModifyGroupRequest req)
        {
            JsonResponseModel <ModifyGroupResponse> rsp = null;

            try
            {
                var strResp = this.InternalRequestSync(req, "ModifyGroup");
                rsp = JsonConvert.DeserializeObject <JsonResponseModel <ModifyGroupResponse> >(strResp);
            }
            catch (JsonSerializationException e)
            {
                throw new TencentCloudSDKException(e.Message);
            }
            return(rsp.Response);
        }
Exemplo n.º 3
0
        /// <summary>
        /// 修改分组
        /// </summary>
        public static void ModifyGroup()
        {
            try
            {
                IMpClient mpClient = new MpClient();
                var       request  = new AccessTokenGetRequest()
                {
                    AppIdInfo = new AppIdInfo()
                    {
                        AppId = AppId, AppSecret = AppSecret
                    }
                };
                var response = mpClient.Execute(request);
                if (response.IsError)
                {
                    return;
                }

                var groupInfo = new Group()
                {
                    Id   = "101",
                    Name = "修改后的分组"
                };

                var request2 = new ModifyGroupRequest()
                {
                    AccessToken = response.AccessToken.AccessToken,
                    GroupInfo   = groupInfo,
                    SendData    = groupInfo.ToModifyJsonString()
                };

                var response2 = mpClient.Execute(request2);
                if (response2.IsError)
                {
                    LogHelper.WriteLog(typeof(UserGroupOperation), response2.ErrInfo.ErrMsg);
                }
                else
                {
                    GetGroups(); //查询一把,显示一下信息
                }
            }
            catch (Exception ex)
            {
                LogHelper.WriteLog(typeof(UserGroupOperation), ex);
                throw new Exception(ex.Message);
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// 修改分组测试
        /// </summary>
        public static void ModifyGroupTest()
        {
            IMpClient             mpClient = new MpClient();
            AccessTokenGetRequest request  = new AccessTokenGetRequest()
            {
                AppIdInfo = new AppIdInfo()
                {
                    AppID = appId, AppSecret = appSecret
                }
            };
            AccessTokenGetResponse response = mpClient.Execute(request);

            if (response.IsError)
            {
                Console.WriteLine("获取令牌环失败..");
                return;
            }

            Group groupInfo = new Group()
            {
                id   = "101",
                name = "修改后的分组"
            };

            ModifyGroupRequest request2 = new ModifyGroupRequest()
            {
                AccessToken = response.AccessToken.AccessToken,
                GroupInfo   = groupInfo,
                SendData    = groupInfo.ToModifyJsonString()
            };

            var response2 = mpClient.Execute(request2);

            if (response2.IsError)
            {
                Console.WriteLine("修改分组失败,错误信息为:" + response2.ErrInfo.ErrCode + "-" + response2.ErrInfo.ErrMsg);
            }
            else
            {
                Console.WriteLine("修改分组信息成功");
                GetGroupsTest(); //查询一把,显示一下信息
            }
        }