Example #1
0
        public IActionResult UpdateRolePowers([FromBody] RolePowersUpdateDto parm)
        {
            if (string.IsNullOrEmpty(parm.RoleId))
            {
                return(toResponse(StatusCodeType.Error, "roleId 不能为空"));
            }

            //生成插入对象
            List <Sys_RolePower> rolePowers = new List <Sys_RolePower>();

            foreach (var power in parm.PowerIds)
            {
                rolePowers.Add(new Sys_RolePower
                {
                    ID       = GetGUID,
                    PowerUID = power,
                    RoleUID  = parm.RoleId
                });
            }

            //执行更新过程
            try
            {
                _rolePowerService.BeginTran();
                // 先删除角色对应的权限
                _rolePowerService.Delete(o => o.RoleUID == parm.RoleId);
                // 再插入传递进来的权限
                _rolePowerService.Add(rolePowers);
                _rolePowerService.CommitTran();


                //更新登录会话记录
                var userIds = _userRoleService.GetWhere(m => m.RoleID == parm.RoleId).Select(m => m.UserID);

                foreach (var userId in userIds)
                {
                    _tokenManager.RefreshSession(userId);
                }

                return(toResponse(StatusCodeType.Success));
            }
            catch (Exception)
            {
                _rolePowerService.RollbackTran();
                throw;
            }
        }
Example #2
0
        public IActionResult Delete(string id)
        {
            if (string.IsNullOrEmpty(id))
            {
                return(toResponse(StatusCodeType.Error, "删除权限 Id 不能为空"));
            }

            try
            {
                _rolePowerService.BeginTran();
                _rolePowerService.Delete(o => o.PowerUID == id);
                _powerService.Delete(id);
                _rolePowerService.CommitTran();
                return(toResponse(StatusCodeType.Success));
            }
            catch (Exception ex)
            {
                _rolePowerService.RollbackTran();
                throw ex;
            }
        }