Exemplo n.º 1
0
        public async Task <PagedResultDto <GetManagerListDto> > GetPagedManagerAsync(GetManagerPagerInput input)
        {
            //查询不是当前用户Id的子帐号数据
            Expression <Func <Manager, bool> > where = w =>
                                                       w.UserBase.Id != AprilSession.UserId.Value;

            var predicate = new PredicateGroup <Manager>();

            predicate.AddPredicate(true, where);
            predicate.AddPredicate(AprilSession.AccountType != AccountTypeEnum.超级管理员, w => w.UserBase.BelongUserId.Value == AprilSession.BelongUserId);

            predicate.AddPredicate(!string.IsNullOrEmpty(input.UserName), s => s.UserBase.UserName.Contains(input.UserName));
            predicate.AddPredicate(!string.IsNullOrEmpty(input.RealName), s => s.UserBase.RealName.Contains(input.RealName));
            predicate.AddPredicate(!string.IsNullOrEmpty(input.PhoneNumber), s => s.UserBase.PhoneNumber.Contains(input.PhoneNumber));

            var tuple = await _managerManage.GetPagedMemberAsync(predicate.Predicates,
                                                                 input, new List <string> {
                "UserBase"
            });

            var roleListDtos = tuple.Item1.MapTo <List <GetManagerListDto> >();

            return(new PagedResultDto <GetManagerListDto>(
                       tuple.Item2,
                       roleListDtos
                       ));
        }
Exemplo n.º 2
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));
        }
Exemplo n.º 3
0
        /// <summary>
        ///     根据Ids获取角色集合
        /// </summary>
        /// <param name="ids">角色编号集合</param>
        /// <returns></returns>
        public async Task <List <Role> > GetRoleListByIdsAsync(List <long> ids)
        {
            var predicate = new PredicateGroup <Role>();

            predicate.AddPredicate(true, s => ids.Contains(s.Id));
            predicate.AddPredicate(true, s => s.IsValid);

            return(await _roleRepository.QueryAsync(predicate.Predicates));
        }
Exemplo n.º 4
0
        public async Task <SideBarDto> GetSideBarListAsync(long[] array)
        {
            var menuid = await _roleManage.GetRoleMenuByArrayAsync(array);

            Expression <Func <Menu, bool> > where =
                w => w.IsMenu && menuid.Contains(w.Id) && w.IsValid;

            var predicate = new PredicateGroup <Menu>();

            predicate.AddPredicate(true, where);

            var menus = await _menuManage
                        .GetMenuListAsync(predicate.Predicates);

            var topMenus = menus.Where(x => x.ParentId == null);

            var enumerable = topMenus as Menu[] ?? topMenus.ToArray();

            var sideBar = new SideBarDto {
                TopHtml = BuilTopHtml(enumerable)
            };

            foreach (var menu in enumerable)
            {
                var html = new StringBuilder();

                sideBar.ChildrenHtml += BuilSideBarHtml(menu.Childrens, html);
            }

            return(sideBar);
        }
Exemplo n.º 5
0
        /// <summary>
        /// 根据Ids获取菜单授权集合
        /// </summary>
        /// <param name="ids">菜单编号集合</param>
        /// <returns></returns>
        public async Task <List <MenuAppAuthorize> > GetMenuAppAuthorizeListByIdsAsync(List <long> ids)
        {
            var predicate = new PredicateGroup <MenuAppAuthorize>();

            predicate.AddPredicate(true, s => ids.Contains(s.Id));
            return(await _repository.QueryAsync(predicate.Predicates));
        }
Exemplo n.º 6
0
        /// <summary>
        ///     获取所有角色集合
        /// </summary>
        /// <returns></returns>
        public async Task <List <Role> > GetRoleAllAsync()
        {
            var predicate = new PredicateGroup <Role>();

            predicate.AddPredicate(true, w => w.IsValid);

            return(await _roleRepository.QueryAsync(predicate.Predicates));
        }
Exemplo n.º 7
0
        /// <summary>
        ///     根据names获取角色集合
        /// </summary>
        /// <param name="names">角色名称集合</param>
        /// <returns></returns>
        public async Task <List <Role> > GetRoleListByNamesAsync(List <string> names)
        {
            var predicate = new PredicateGroup <Role>();

            predicate.AddPredicate(true, s => names.Contains(s.Name));

            return(await _roleRepository.QueryAsync(predicate.Predicates));
        }
Exemplo n.º 8
0
        /// <summary>
        ///     根据code获取角色
        /// </summary>
        /// <param name="code"></param>
        /// <returns></returns>
        public async Task <Role> GetRoleByCodeAsync(string code)
        {
            var predicate = new PredicateGroup <Role>();

            predicate.AddPredicate(true, s => s.Code == code);
            var role = await _roleRepository.QueryEntityAsync(predicate.Predicates);

            return(role);
        }
Exemplo n.º 9
0
        /// <summary>
        ///     获取授权菜单带子集的列表
        /// </summary>
        /// <param name="where"></param>
        /// <param name="belongUserId"></param>
        /// <param name="menuAppAuthorizeIds"></param>
        /// <param name="menuIds"></param>
        /// <returns></returns>
        public async Task <List <MenuJsTreeAuthorizeEntityDto> > GetMenuChildrenListAuthorizeAsync(
            Expression <Func <Menu, bool> > where, long belongUserId, List <long> menuAppAuthorizeIds, List <long> menuIds)
        {
            var accountType = (AccountTypeEnum)Convert.ToInt32(
                ClaimTypeExtensions.GetClaimValue(
                    ClaimTypeExtensions.AccountType));

            var predicate = new PredicateGroup <Menu>();

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

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

                var menuArray = await _roleRepository.GetAll()
                                .Where(x => array.Contains(x.Id))
                                .AsNoTracking().Include("Menus")
                                .SelectMany(x => x.Menus.Where(w => w.IsPublic).Select(y => y.Id)).ToListAsync();

                Expression <Func <Menu, bool> > arrayWhere =
                    w => menuArray.Contains(w.Id);

                predicate.AddPredicate(true, arrayWhere);
            }

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

            var menus = infoList.Where(x => x.ParentId == null).ToList();

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

            var menuTreeListDto = new List <MenuJsTreeAuthorizeEntityDto>();

            //递归返回菜单树
            GetTreeChildrenMenuList(menuTreeListDto, menus, menuAppAuthorizeIds, menuIds, isAll);

            return(menuTreeListDto);
        }
Exemplo n.º 10
0
        /// <summary>
        ///     根据会员Id获取会员信息
        /// </summary>
        public async Task <Member> GetMemberByUserBaseIdAsync(long userBaseId)
        {
            var predicate = new PredicateGroup <Member>();

            predicate.AddPredicate(true, s => s.UserId == userBaseId);

            var managerList = await _memberRepository.QueryAsync(predicate.Predicates);

            return(managerList.FirstOrDefault());
        }
Exemplo n.º 11
0
        /// <summary>
        ///     根据菜单Id获取菜单授权列表
        /// </summary>
        /// <param name="menuId"></param>
        /// <returns></returns>
        public async Task <List <MenuAppAuthorize> > GetMenuAppAuthorizeList(long menuId)
        {
            Expression <Func <MenuAppAuthorize, bool> > where =
                w => w.MenuId == menuId;
            var predicate = new PredicateGroup <MenuAppAuthorize>();

            predicate.AddPredicate(true, where);

            return(await _repository.QueryAsync(predicate.Predicates));
        }
Exemplo n.º 12
0
        /// <summary>
        /// 查询判断菜单授权
        /// </summary>
        /// <param name="menuCode"></param>
        /// <param name="appCode"></param>
        /// <param name="operationCode"></param>
        /// <returns></returns>
        public async Task <MenuAppAuthorize> JudgeMenuAppAuthorizeAsync(string menuCode, string appCode, string operationCode)
        {
            var predicate = new PredicateGroup <MenuAppAuthorize>();

            predicate.AddPredicate(true, s => s.AppCode == appCode &&
                                   s.MenuCode == menuCode &&
                                   s.OperationCode == operationCode);

            return(await _repository.QueryEntityAsync(predicate.Predicates));
        }
Exemplo n.º 13
0
        /// <summary>
        ///     根据后台用户Id获取用户实体
        /// </summary>
        /// <returns></returns>
        public async Task <Manager> GetManagerByIdAsync(long managerId, List <string> includeNames)
        {
            var predicate = new PredicateGroup <Manager>();

            predicate.AddPredicate(true, s => s.Id == managerId);

            var managerList = await _managerRepository.QueryAsync(
                predicate.Predicates, includeNames);

            return(managerList.FirstOrDefault());
        }
Exemplo n.º 14
0
        /// <summary>
        ///     根据DefaultRoleType获取默认角色集合
        /// </summary>
        /// <param name="defaultRoleTypes"></param>
        /// <returns></returns>
        public async Task <List <Role> > GetRoleListByDefaultRoleTypeAsync(List <int> defaultRoleTypes)
        {
            Expression <Func <Role, bool> > where =
                w => w.DefaultRoleType != null && defaultRoleTypes.Contains((int)w.DefaultRoleType);

            var predicate = new PredicateGroup <Role>();

            predicate.AddPredicate(true, where);

            return(await _roleRepository.QueryAsync(predicate.Predicates));
        }
Exemplo n.º 15
0
        /// <summary>
        ///     根据用户名获取
        /// </summary>
        /// <param name="userNameOrPhoneNumber"></param>
        /// <returns></returns>
        public async Task <UserBase> GetUserBaseByIncludeAsync(string userNameOrPhoneNumber)
        {
            var predicate = new PredicateGroup <UserBase>();

            predicate.AddPredicate(true, x => x.UserName == userNameOrPhoneNumber);
            var user = await _userBaseRepository.QueryAsync(predicate.Predicates,
                                                            new List <string> {
                "Roles", "UserClaims"
            });

            return(user.FirstOrDefault());
        }
Exemplo n.º 16
0
        /// <summary>
        ///     获取用户
        ///     <remarks>如果没有查询到用户信息返回null</remarks>
        /// </summary>
        /// <returns></returns>
        public async Task <UserBase> GetUserBaseByIdAsync(long userId, List <string> includeNames = null)
        {
            var predicate = new PredicateGroup <UserBase>();

            predicate.AddPredicate(true, x => x.Id == userId && !x.IsLockoutEnaled);

            var userBases = await _userBaseRepository.QueryAsync(
                predicate.Predicates,
                includeNames);

            return(userBases.FirstOrDefault());
        }
Exemplo n.º 17
0
        /// <summary>
        ///     获取菜单列表
        /// </summary>
        /// <param name="where"></param>
        /// <returns></returns>
        public async Task <List <Menu> > GetMenuListAsync(Expression <Func <Menu, bool> > where)
        {
            var predicate = new PredicateGroup <Menu>();

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

            var list = await _menuRepository.QueryAsync(predicate.Predicates, " Sort Asc");

            var menus = list.Where(m => m.ParentId == null).ToList();

            return(GetTreeMenuList(menus));
        }
Exemplo n.º 18
0
        /// <summary>
        ///     根据Id获取角色
        /// </summary>
        /// <param name="id">角色编号</param>
        /// <param name="includeNames">includeNames</param>
        /// <returns></returns>
        public async Task <Role> GetRoleByIdAsync(long id, List <string> includeNames = null)
        {
            var predicate = new PredicateGroup <Role>();

            predicate.AddPredicate(true, s => s.Id == id);

            var info = await _roleRepository.QueryEntityAsync(predicate.Predicates, includeNames);

            if (info == null)
            {
                throw new UserFriendlyException("未找到角色");
            }

            return(info);
        }
Exemplo n.º 19
0
        public async Task <PagedResultDto <RoleListDto> > GetPagedRoleAsync(GetRolesInput input)
        {
            Expression <Func <Role, bool> > whereif = w => w.Name == input.FilterText;

            var predicate = new PredicateGroup <Role>();

            predicate.AddPredicate(!string.IsNullOrEmpty(input.FilterText), whereif);

            var tuple = await _roleManage.GetPagedRoleAsync(predicate.Predicates, input);

            var roleListDtos = tuple.Item1.MapTo <List <RoleListDto> >();

            return(new PagedResultDto <RoleListDto>(
                       tuple.Item2,
                       roleListDtos
                       ));
        }
Exemplo n.º 20
0
        /// <summary>
        /// 批量保存
        /// </summary>
        /// <param name="list"></param>
        /// <param name="menuId"></param>
        /// <returns></returns>
        public async Task BatchInsertMenuAppAuthorizeAsync(List <MenuAppAuthorize> list, long menuId)
        {
            var keyArray = new List <long>();

            using (var unitOfWork = _unitOfWorkManager.Begin()) //启用工作单元
            {
                var first = list.FirstOrDefault();
                foreach (var item in list)
                {
                    Expression <Func <MenuAppAuthorize, bool> > where =
                        w => w.MenuId == item.MenuId &&
                        w.MenuCode == item.MenuCode &&
                        w.AppCode == item.AppCode &&
                        w.OperationCode == item.OperationCode;

                    var predicate = new PredicateGroup <MenuAppAuthorize>();
                    predicate.AddPredicate(true, where);

                    var entity = await _repository.QueryEntityAsync(predicate.Predicates);

                    if (entity != null)
                    {
                        keyArray.Add(entity.Id);
                    }
                    else
                    {
                        var key = await _repository.InsertAndGetIdAsync(item);

                        keyArray.Add(key);
                    }
                }
                if (first != null)
                {
                    await _repository.DeleteAsync(x => !(keyArray.Contains(x.Id)) &&
                                                  x.MenuId == first.MenuId);
                }
                else
                {
                    await _repository.DeleteAsync(x => x.MenuId == menuId);
                }

                await unitOfWork.CompleteAsync();
            }
        }
Exemplo n.º 21
0
        /// <summary>
        ///     私有方法
        /// </summary>
        /// <param name="array"></param>
        /// <returns></returns>
        private async Task <List <TopMenusViewModel> > LoadData(long[] array)
        {
            var menuid = await _roleManage.GetRoleMenuByArrayAsync(array);

            Expression <Func <Menu, bool> > where =
                w => w.IsMenu && menuid.Contains(w.Id) && w.IsValid;

            var predicate = new PredicateGroup <Menu>();

            predicate.AddPredicate(true, where);

            var menus = await _menuManage
                        .GetMenuListAsync(predicate.Predicates);

            var topMenus          = menus.ToList().Where(x => x.ParentId == null);
            var topMenusViewModel = topMenus.MapTo <List <TopMenusViewModel> >();

            foreach (var item in topMenusViewModel)
            {
                item.ChildMenus.AddRange(BuildSideBar(item.Id, item.Code, menus));
            }
            return(topMenusViewModel);
        }
Exemplo n.º 22
0
        public async Task <List <MenuListDto> > GetDynamicRouteAsync()
        {
            var strArray = AprilSession.UserRoles.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
            var array    = Array.ConvertAll(strArray, long.Parse);

            var menuid = await _roleManage.GetRoleMenuByArrayAsync(array);

            Expression <Func <Menu, bool> > where =
                w => w.IsMenu && menuid.Contains(w.Id);


            var predicate = new PredicateGroup <Menu>();

            predicate.AddPredicate(true, where);

            var menus = await _menuManage
                        .GetMenuListAsync(predicate.Predicates);

            var menuListDtos = menus
                               .MapTo <List <MenuListDto> >();

            return(menuListDtos);
        }