Beispiel #1
0
        /// <summary>
        /// 修改用户绑定角色
        /// </summary>
        /// <param name="bindInfo">绑定信息</param>
        public Result ModifyUserBindRole(ModifyUserBindRoleCmdDto bindInfo)
        {
            if (bindInfo == null || (bindInfo.Binds.IsNullOrEmpty() && bindInfo.UnBinds.IsNullOrEmpty()))
            {
                return(Result.FailedResult("没有指定任何要修改的绑定信息"));
            }
            using (var businessWork = UnitOfWork.Create())
            {
                //解绑
                if (!bindInfo.UnBinds.IsNullOrEmpty())
                {
                    UserRoleService.UnBindUserAndRole(bindInfo.UnBinds.Select(c => new Tuple <User, Role>(User.CreateUser(c.Item1?.SysNo ?? 0), Role.CreateRole(c.Item2?.SysNo ?? 0))).ToArray());
                }
                //绑定
                if (!bindInfo.Binds.IsNullOrEmpty())
                {
                    UserRoleService.BindUserAndRole(bindInfo.Binds.Select(c => new Tuple <User, Role>(User.CreateUser(c.Item1?.SysNo ?? 0), Role.CreateRole(c.Item2?.SysNo ?? 0))).ToArray());
                }

                var commitResult = businessWork.Commit();
                return(commitResult.ExecutedSuccess ? Result.SuccessResult("修改成功") : Result.FailedResult("修改失败"));
            }
        }