/// <summary> /// 保存用户角色关系 /// </summary> /// <param name="accountId">用户Id</param> /// <param name="roleIds">角色Id集合</param> /// <param name="operational">操作信息</param> /// <returns>结果</returns> public static Result SavePermissionRole(Guid accountId, List <Guid> roleIds, Operational operational) { Result result = new Result(); try { using (IPowerUnitOfWork unit = DbContext.CreateIPowerUnitOfWork()) { IRoleUserRelationshipRepository roleUserRelationshipRepository = DbContext.CreateIRoleUserRelationshipRepository(unit); roleUserRelationshipRepository.RemoveByAccountId(accountId); var content = PermissionBuilder.ToMRoleUserRelationship(accountId, roleIds); roleUserRelationshipRepository.Add(content); unit.Complete(); } result.IsSucceed = true; result.Message = "保存成功"; } catch (Exception ex) { result.IsSucceed = false; result.Message = Const.ErrorMessage; LogService.WriteLog(ex, "保存用户角色关系"); } return(result); }
/// <summary> /// 查询可用角色Id /// </summary> /// <returns>用户Id</returns> public static IEnumerable <Guid> QueryRoleIds(Guid accountId) { using (IRoleUserRelationshipRepository roleUserRelationshipRepository = DbContext.CreateIRoleUserRelationshipRepository()) { return(roleUserRelationshipRepository.QueryRoleIds(accountId)); } }