public async Task DeleteAPIAuthorityAsync(Guid id) { List <APIAuthority> allAPIAuthorities = await _apiAuthorityRepository.GetAllInfoFromCacheAsync(); APIAuthority apiAuthorityFromDB = allAPIAuthorities.FirstOrDefault(m => m.ID == id); if (apiAuthorityFromDB == null) { throw new InvalidOperationException("API权限不存在"); } ICollection <APIAuthority> allChild = GetAllChild(allAPIAuthorities, id); foreach (APIAuthority apiAuthority in allChild) { _authorityUnitOfWork.RegisterDelete(apiAuthority); } _authorityUnitOfWork.RegisterDelete(apiAuthorityFromDB); await _authorityUnitOfWork.CommitAsync(); _apiAuthorityRepository.ClearCache(); }
public async Task <RoleDTO> GetRoleInfoAsync(Guid id) { Role roleFromDB = await _roleRepository.FirstOrDefaultAsync(id); if (roleFromDB == null) { throw new InvalidOperationException("角色不存在"); } var result = _mapper.Map <RoleDTO>(roleFromDB); List <WebMenuAuthority> allWebMenuAuthorities = await _webMenuAuthorityRepository.GetAllInfoFromCacheAsync(); List <RoleWebMenuAuthority> roleOwnedWebMenus = await _roleWebMenuAuthorityRepository.WhereAsync(m => m.RoleID == id).ToList(); Guid[] roleHasWebMenuID = roleOwnedWebMenus.Select(m => m.WebMenuAuthorityID).ToArray(); result.WebMenuAuthorityTreeList = TreeHelper.GetTreeList <RoleWebMenuAuthorityTreeDTO, WebMenuAuthority, Guid>(allWebMenuAuthorities, null, webMenuAuthority => { var temp = webMenuAuthority.CopyProperties <RoleWebMenuAuthorityTreeDTO>(nameof(WebMenuAuthority.Child), nameof(WebMenuAuthority.RoleWebMenuAuthorities)); temp.Owned = roleHasWebMenuID.Contains(webMenuAuthority.ID); return(temp); }); List <APIAuthority> allAPIAuthorities = await _apiAuthorityRepository.GetAllInfoFromCacheAsync(); List <RoleAPIAuthority> roleOwnedAPIs = await _roleAPIAuthorityRepository.WhereAsync(m => m.RoleID == id).ToList(); Guid[] roleHasAPIID = roleOwnedAPIs.Select(m => m.APIAuthorityID).ToArray(); result.APIAuthorityTreeList = TreeHelper.GetTreeList <RoleAPIAuthorityTreeDTO, APIAuthority, Guid>(allAPIAuthorities, null, apiAuthority => { var temp = apiAuthority.CopyProperties <RoleAPIAuthorityTreeDTO>(nameof(APIAuthority.Child), nameof(APIAuthority.RoleAPIAuthorities)); temp.Owned = roleHasAPIID.Contains(apiAuthority.ID); return(temp); }); List <ActionAuthority> allActionAuthorities = await _actionAuthorityRepository.WhereAsync(m => true).ToList(); List <RoleActionAuthority> roleOwnedActions = await _roleActionAuthorityRepository.WhereAsync(m => m.RoleID == id).ToList(); Guid[] roleHasActionID = roleOwnedActions.Select(m => m.ActionAuthorityID).ToArray(); result.ActionAuthorityList = allActionAuthorities.Select(m => new RoleActionAuthorityListDTO { ActionGroupCode = m.ActionGroupCode, Code = m.Code, ID = m.ID, Name = m.Name, Owned = roleHasActionID.Contains(m.ID) }).ToList(); return(result); }