Exemple #1
0
        public async Task <List <Menu> > GetMenuListAuthorizeAsync(Expression <Func <Menu, bool> > where, long belongUserId)
        {
            var accountType =
                (AccountTypeEnum)Convert.ToInt32(ClaimTypeExtensions.GetClaimValue(ClaimTypeExtensions.AccountType));

            var predicate = new PredicateGroup <Menu>();

            predicate.AddPredicate(where != null, where);

            if (accountType != AccountTypeEnum.超级管理员)
            {
                var roles = await _userManage.GetUserRoleListAsync(belongUserId);

                var menus = await _roleRepository.GetAll()
                            .Where(x => roles.Contains(x.Id))
                            .AsNoTracking().Include("Menus")
                            .SelectMany(x => x.Menus.Where(m => m.IsPublic).Select(y => y.Id)).ToListAsync();

                Expression <Func <Menu, bool> > arrayWhere = w => menus.Contains(w.Id);
                predicate.AddPredicate(true, arrayWhere);
            }

            var list = await _menuRepository.QueryAsync(predicate.Predicates, new List <string> {
                "MenuAppAuthorizes"
            });

            var menuList = list.Where(x => x.ParentId == null).ToList();

            var isAll = accountType == AccountTypeEnum.超级管理员;

            return(GetTreeMenuList(menuList, isAll));
        }
Exemple #2
0
 /// <summary>
 ///     获取用户角色Id集合
 /// </summary>
 /// <param name="userBaseId"></param>
 /// <returns></returns>
 public async Task <long[]> GetUserRoleListAsync(long userBaseId)
 {
     return(await _userBaseRepository.GetAll()
            .Where(x => x.Id == userBaseId).AsNoTracking()
            .Include("Roles")
            .SelectMany(x =>
                        x.Roles.Select(y => y.Id)).ToArrayAsync());
 }
Exemple #3
0
        /// <summary>
        ///     根据角色Id获取拥有菜单Id集合
        /// </summary>
        /// <param name="array"></param>
        /// <returns></returns>
        public async Task <List <long> > GetRoleMenuByArrayAsync(long[] array)
        {
            var query = _roleRepository.GetAll()
                        .Where(x => array.Contains(x.Id));
            var list = await query.AsNoTracking().Include("Menus")
                       .SelectMany(x => x.Menus.Select(y => y.Id)).ToListAsync();

            return(list);
        }
Exemple #4
0
        /// <summary>
        ///   删除
        /// </summary>
        /// <param name="managerId"></param>
        /// <returns></returns>
        public async Task DeleteManagerAsync(long managerId)
        {
            //获取管理员表数据删除
            var entity = await GetManagerByIdAsync(managerId, new List <string>());

            await _managerRepository.DeleteAsync(entity);

            //获取用户基础表数据删除
            var user = await _userBaseRepository.GetAll()
                       .Where(x => x.Id == entity.UserId)
                       .Include("Roles")
                       .Include("UserClaims")
                       .FirstOrDefaultAsync();

            //删除用户的申明表集合
            if (user.UserClaims != null && user.UserClaims.Any())
            {
                var deleteIds = user.UserClaims.Select(x => x.Id);
                await _userClaimRepository.DeleteAsync(x => deleteIds.Contains(x.Id));
            }

            await _userBaseRepository.DeleteAsync(user);
        }