Exemplo n.º 1
0
        /// <summary>
        /// 创建组织树状结构
        /// </summary>
        /// <param name="OranizationId">OranizationId</param>
        /// <returns></returns>
        public async Task <ResponseMessage <List <TreeResponse> > > CreatOranizationTree(string OranizationId)
        {
            var users    = DataBaseUser.TokenModel;
            var response = new ResponseMessage <List <TreeResponse> >();

            try
            {
                //1.1.找到该用户的所有权限
                var scopeList = await _IRolesStore.BrowsingScope(users.Id, "Organization_Add_Edit");

                if (scopeList == null)
                {
                    response.Message = "暂无权限,请联系管理";
                    response.Code    = ResponseCodeDefines.NotAllow;
                    return(response);
                }

                //1.2.对应权限的所有的可以浏览的范围(默认包含可查看本组织的内容)
                scopeList.Add(users.OrganizationId);
                //在扩展表中找到其父节点并展示
                var IparentList = _IOranizationStore.GettingOrganizationExpansions().Where(p => p.IsImmediate == true && scopeList.Contains(p.SonId));

                //默认展示顶部【如果没有其操作权限提示即可】
                var query = _IOranizationStore.GettingOraniztions().Where(u => !u.IsDeleted);
                if (OranizationId == "0")
                {
                    var oraniztionList = query.Where(u => u.ParentId == OranizationId).Select(p => new TreeResponse
                    {
                        title = p.OrganizationName, //组织名称
                        key   = p.Id,               //组织ID
                    }).ToListAsync();
                    response.Extension = await oraniztionList;
                }
                else
                {
                    var oraniztionList = IparentList.Where(o => o.OrganizationId == OranizationId).Select(p => new TreeResponse
                    {
                        title = p.SonName, //组织名称
                        key   = p.SonId,   //组织ID
                    }).ToListAsync();
                    response.Extension = await oraniztionList;
                }
            }
            catch (Exception el)
            {
                throw new Exception(el.Message);
            }
            return(response);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 获取所有用户信息
        /// </summary>
        /// <returns></returns>
        public virtual async Task <PagingResponseMessage <UsersResponse> > GettingUsers(OranizationUserRequest condition)
        {
            var users          = DataBaseUser.TokenModel;
            var pagingResponse = new PagingResponseMessage <UsersResponse>();

            ////判断该用户的权限,锁定该组织范围
            //1.1.找到该用户的所有权限
            var scopeList = await _RolesStore.BrowsingScope(users.Id, "User_Add_Edit");

            if (scopeList == null)
            {
                pagingResponse.Message = "暂无权限,请联系管理";
                pagingResponse.Code    = ResponseCodeDefines.NotAllow;
                return(pagingResponse);
            }

            //1.2.对应权限的所有的可以浏览的范围(默认包含可查看本组织的内容)
            scopeList.Add(users.OrganizationId);
            var query = _IUserStore.GetUserInformation().Where(p => scopeList.Contains(p.OrganizationId));

            if (condition.OranizationId != null)
            {
                query = _IUserStore.GetUserInformation().Where(u => u.OrganizationId == condition.OranizationId && !u.IsDeleted);
            }
            //员工管理筛选条件【角色】
            if (condition.RoleId != null)
            {
                query = from c in query
                        join b in _RolesStore.GetUserRoleAsync() on
                        c.Id equals b.UserId into c1
                        from c2 in c1.DefaultIfEmpty()
                        where c2.RoleId.Equals(condition.RoleId)
                        select c;
            }

            //员工管理筛选条件【姓名】
            if (condition.TrueName != null)
            {
                query = query.Where(p => p.TrueName.Contains(condition.TrueName));
            }

            //员工管理筛选条件【部门】
            if (condition.EpartmentId != null)
            {
                query = query.Where(p => p.OrganizationId.Equals(condition.EpartmentId));
            }

            //员工管理筛选条件【离职】
            if (condition.IsDelete != null)
            {
                query = query.Where(p => p.IsDeleted.Equals(condition.IsDelete));
            }

            pagingResponse.TotalCount = await query.CountAsync();

            var qlist = await query.Skip(condition.PageIndex *condition.PageSize).Take(condition.PageSize).ToListAsync();

            pagingResponse.PageIndex = condition.PageIndex;
            pagingResponse.PageSize  = condition.PageSize;
            pagingResponse.Extension = _Mapper.Map <List <UsersResponse> >(qlist);
            return(pagingResponse);
        }
Exemplo n.º 3
0
        /// <summary>
        /// 添加用户角色表
        /// </summary>
        /// <param name="userRolesRequest"></param>
        /// <returns></returns>
        public async Task <ResponseMessage> AddUserRoles(UserRolesRequest userRolesRequest)
        {
            var users    = DataBaseUser.TokenModel;
            var response = new ResponseMessage();

            if (userRolesRequest == null)
            {
                throw new Exception(nameof(userRolesRequest));
            }
            try
            {
                var scopeList = await _IRolesStore.BrowsingScope(users.Id, "Role_Add_Edit");

                if (scopeList == null)
                {
                    response.Message = "暂无权限,请联系管理";
                    response.Code    = ResponseCodeDefines.NotAllow;
                    return(response);
                }

                ////1.1: 找到所有的角色ID
                var oldRols = await _IRolesStore.GetUserRoleAsync().Where(u => u.UserId.Equals(userRolesRequest.UserId)).Select(p => p.RoleId).ToListAsync();

                //请求的权限个数大于原来的原有权限个数就是新增权限,小于的话就是要删除,
                if (oldRols.Count() > userRolesRequest.RoleId.Count())
                {
                    var deleteRoleId = oldRols.Except(userRolesRequest.RoleId).ToList(); //差集
                    //1.1. 删除用户角色表
                    await _IRolesStore.DeleteUserRoles(userRolesRequest.UserId, deleteRoleId);

                    //1.2.删除权限扩展表
                    var permissionList = await _IRolesStore.GetRolePermissionsAsync().Where(p => deleteRoleId.Contains(p.RoledId)).Select(u => u.PermissionsId).ToListAsync();

                    await _IRolesStore.DeletePermissionEx(userRolesRequest.UserId, permissionList);
                }
                //新增
                else
                {
                    var addRoleId = userRolesRequest.RoleId.Except(oldRols); //差集
                    var model     = new List <UserRole>();
                    foreach (var roleId in addRoleId)
                    {
                        model.Add(new UserRole {
                            RoleId = roleId, UserId = userRolesRequest.UserId
                        });
                    }

                    ////1.2: 找到所有的角色的权限
                    var permissionList = await _IRolesStore.GetRolePermissionsAsync().Where(p => addRoleId.Contains(p.RoledId)).ToListAsync();

                    if (permissionList.Count() == 0)
                    {
                        response.Message = "该角色的权限项未指定.请先完善";
                        response.Code    = ResponseCodeDefines.ArgumentNullError;
                        return(response);
                    }
                    ////1.3: 构建权限扩展表
                    List <PermissionExpansion> PermissionEx = new List <PermissionExpansion>();
                    foreach (var item in permissionList)
                    {
                        PermissionEx.Add(new PermissionExpansion
                        {
                            Id               = Guid.NewGuid().ToString(),
                            OrganizationId   = item.OrganizationScope,
                            OrganizationName = "",
                            PermissionId     = item.PermissionsId,
                            PermissionName   = "",
                            UserId           = userRolesRequest.UserId,
                            UserName         = userRolesRequest.UserName
                        });
                    }
                    await _IRolesStore.InsertUserRole(model);

                    await _IRolesStore.InsertRolePermissionEX(PermissionEx);
                }
            }
            catch (Exception el)
            {
                throw new Exception(el.Message);
            }
            return(response);
        }