/// <summary> /// 加载一个部门及子部门全部Roles /// </summary> public GridData Load(Guid orgId, int pageindex, int pagesize) { if (pageindex < 1) { pageindex = 1; //TODO:如果列表为空新增加一个用户后,前端会传一个0过来,奇怪?? } IEnumerable <Role> roles; int total = 0; if (orgId == Guid.Empty) { roles = _repository.LoadRoles(pageindex, pagesize); total = _repository.GetCount(); } else { roles = _repository.LoadInOrgs(pageindex, pagesize, GetSubOrgIds(orgId)); total = _repository.GetRoleCntInOrgs(orgId); } var rolevms = new List <RoleVM>(); foreach (var role in roles) { RoleVM rolevm = role; var orgs = _orgRepository.LoadByRole(role.Id); rolevm.Organizations = string.Join(",", orgs.Select(u => u.Name).ToList()); rolevm.OrganizationIds = string.Join(",", orgs.Select(u => u.Id).ToList()); rolevms.Add(rolevm); } var result = new GridData { records = total, total = (int)Math.Ceiling((double)total / pagesize), rows = rolevms.ToList(), page = pageindex }; return(result); }