示例#1
0
        private List <RoleListData> GetRoleAssignmes(string userId, string groupId)
        {
            SelectSpecification <GroupUserEntity, RoleListData> getGroupRoleSpecification = new SelectSpecification <GroupUserEntity, RoleListData>();

            getGroupRoleSpecification.AddFilter(x => x.UserId == userId);
            getGroupRoleSpecification.AddFilter(x => x.GroupId == groupId);

            getGroupRoleSpecification.AddSelect(x => new RoleListData(
                                                    x.Role.Id,
                                                    x.Role.Name));

            RoleListData groupRole = _groupUserRepository.SingleOrDefault(getGroupRoleSpecification);

            if (groupRole == null)
            {
                _logger.LogInformation($"User has no groupRole. UserId {userId}, GroupId {groupId}");
                return(new List <RoleListData>());
            }

            SelectSpecification <RoleAssignmentEntity, RoleListData> getRoleAssignmesSpecification = new SelectSpecification <RoleAssignmentEntity, RoleListData>();

            getRoleAssignmesSpecification.AddFilter(x => x.RoleId == groupRole.Id);

            getRoleAssignmesSpecification.AddSelect(x => new RoleListData(
                                                        x.CanAssigneRole.Id,
                                                        x.CanAssigneRole.Name));

            List <RoleListData> canAssigneRoles = _roleAssignmentRepository.GetList(getRoleAssignmesSpecification);

            if (!canAssigneRoles.Any(x => x.Id == groupRole.Id))
            {
                canAssigneRoles.Add(groupRole);
            }

            return(canAssigneRoles);
        }
示例#2
0
        private async Task <List <RoleListData> > GetRoleAssignments(string userId, string groupId)
        {
            IBaseSpecification <GroupUserEntity, RoleListData> getGroupRoleSpecification = SpecificationBuilder
                                                                                           .Create <GroupUserEntity>()
                                                                                           .Where(x => x.UserId == userId)
                                                                                           .Where(x => x.GroupId == groupId)
                                                                                           .Select(x => new RoleListData(
                                                                                                       x.Role.Id,
                                                                                                       x.Role.Name))
                                                                                           .Build();

            RoleListData role = await _groupUserDAO.SingleOrDefault(getGroupRoleSpecification);

            if (role == null)
            {
                _logger.LogInformation($"User has no groupRole. UserId {userId}, GroupId {groupId}");
                return(new List <RoleListData>());
            }

            IBaseSpecification <RoleAssignmentEntity, RoleListData> getRoleAssigmentsSpecification = SpecificationBuilder
                                                                                                     .Create <RoleAssignmentEntity>()
                                                                                                     .Where(x => x.RoleId == role.Id)
                                                                                                     .Select(x => new RoleListData(
                                                                                                                 x.CanAssigneRole.Id,
                                                                                                                 x.CanAssigneRole.Name))
                                                                                                     .Build();

            List <RoleListData> canAssigneRoles = await _roleAssignmentDAO.Get(getRoleAssigmentsSpecification);

            if (!canAssigneRoles.Any(x => x.Id == role.Id))
            {
                canAssigneRoles.Add(role);
            }

            return(canAssigneRoles);
        }