示例#1
0
        public async Task <GetPermissionsOutput> GetPermissions(GetPermissionsInput input)
        {
            Expression <Func <User, object> >[] adminProperty = new Expression <Func <User, object> >[] {
                e => e.UserRoles
            };
            var admin = _adminManager.GetAdminsIncluding(adminProperty).FirstOrDefault(e => e.Id == input.Id);

            if (admin == null)
            {
                throw new UserFriendlyException("未找到管理员");
            }

            var roleIds = admin.UserRoles.Select(e => e.RoleId).ToList();

            Expression <Func <Role, object> >[] roleProperty = new Expression <Func <Role, object> >[] {
                e => e.RolePermissions
            };
            var roles = _roleManager.RoleRepository.GetAllIncluding(roleProperty).Where(e => roleIds.Contains(e.Id)).ToList();

            var permissionIds = new List <int>();

            roles.ForEach(role =>
            {
                role.RolePermissions.ToList().ForEach(polePermission => { permissionIds.Add(polePermission.PermissionId); });
            });
            permissionIds = permissionIds.Distinct().ToList();

            var permissions = await _permissionManager.PermissionRepository.GetAllListAsync(e => permissionIds.Contains(e.Id));

            return(new GetPermissionsOutput()
            {
                Permissions = _objectMapper.Map <List <PermissionDto> >(permissions)
            });
        }
示例#2
0
 public GetPermissionsOutput GetPermissions(GetPermissionsInput input)
 {
     return(new GetPermissionsOutput
     {
         Permissions = _permissionManager.GetAllPermissions()
     });
 }
        public async Task <GetPermissionsOutput> GetPermissions(GetPermissionsInput input)
        {
            var permissions = _permissionManager.PermissionRepository.GetAll()
                              .OrderByDescending(e => e.Id).Where(e => (e.Name != null && e.Name.Contains(input.SearchKey)) || string.IsNullOrEmpty(input.SearchKey)).Skip(input.PageSize * (input.PageIndex - 1))
                              .Take(input.PageSize).ToList();

            return(new GetPermissionsOutput()
            {
                Permissions = AutoMapper.Mapper.Map <List <PermissionDto> >(permissions)
            });
        }
示例#4
0
        public async void TestGetPermissions()
        {
            var getPermissionsInput = new GetPermissionsInput();
            var permissionsList     = await _permissionAppService.GetPermissionsAsync(getPermissionsInput);

            Assert.True(permissionsList.Items.Count >= 0);

            getPermissionsInput.Filter = "qwerty";
            var permissionsListEmpty = await _permissionAppService.GetPermissionsAsync(getPermissionsInput);

            Assert.True(permissionsListEmpty.Items.Count == 0);
        }
        public async Task <GetPermissionsOutput> GetPermissions(GetPermissionsInput input)
        {
            IEnumerable <Permission> permissions = _permissionManager.PermissionRepository.GetAll().Where(e => (e.Name != null && e.Name.Contains(input.SearchKey)) || string.IsNullOrEmpty(input.SearchKey));

            int num = permissions.Count();

            permissions = permissions.OrderByDescending(e => e.Id).Skip(input.PageSize * (input.PageIndex - 1)).Take(input.PageSize).ToList();

            return(new GetPermissionsOutput()
            {
                Permissions = _objectMapper.Map <List <PermissionDto> >(permissions), ResourceNum = num, PageIndex = input.PageIndex
            });
        }
示例#6
0
        public async Task <IPagedList <PermissionListDto> > GetPermissionsAsync(GetPermissionsInput input)
        {
            var query = _permissionRepository.GetAll(
                !input.Filter.IsNullOrEmpty(),
                predicate => predicate.Name.Contains(input.Filter) ||
                predicate.DisplayName.Contains(input.Filter))
                        .OrderBy(input.Sorting);

            var permissionsCount = await query.CountAsync();

            var permissions        = query.PagedBy(input.PageSize, input.PageIndex).ToList();
            var permissionListDtos = _mapper.Map <List <PermissionListDto> >(permissions);

            return(permissionListDtos.ToPagedList(permissionsCount));
        }
示例#7
0
        public async Task <GetPermissionsOutput> GetPermissions(GetPermissionsInput input)
        {
            Expression <Func <Role, object> >[] propertySelectors = new Expression <Func <Role, object> >[] {
                e => e.RolePermissions
            };
            var role = _roleManager.RoleRepository.GetAllIncluding(propertySelectors).FirstOrDefault(e => e.Id == input.Id);

            List <int> permissionIds = role.RolePermissions.Select(e => e.PermissionId).ToList();
            var        permissions   = await _permissionRepository.GetAllListAsync(e => permissionIds.Contains(e.Id));

            return(new GetPermissionsOutput()
            {
                Permissions = _objectMapper.Map <List <PermissionDto> >(permissions)
            });
        }