public SoaDataPageResponse <RoleModel> GetRoleList(SoaDataPage <RoleGridFilterViewModel> fiter) { SoaDataPageResponse <RoleModel> response = new SoaDataPageResponse <RoleModel>(); List <Esmart_Sys_Roles> roles; if (CommonAction.IsSysAdmin(fiter.Where.LogInUserId)) { roles = RoleDbAction.GetAllRols(); response.Count = roles.Count; roles = roles.Skip((fiter.PageIndex - 1) * fiter.PageSize).Take(fiter.PageSize).ToList(); } else { int count; roles = UserRolesDbAction.GetRolesByUserId(fiter, out count); response.Count = count; } var body = roles.ConvertAll(a => new RoleModel() { CreateTime = a.CreateTime, CreatorId = a.CreateId, EndDate = a.EndTime, Id = a.RoleId, Name = a.RoleName, Remark = a.Remark, StartDate = a.StartTime, IsBuiltin = a.IsBuiltin }); response.Body = body; return(response); }
/// <summary> /// 获取用户或部门的可分配角色列表 /// </summary> public List <RoleResponse> GetAssignRoles(int managerUserId, int deparentmentId, int targetUserId) { //------------------------------------- // 根据管理人获取可分配角色列表 //------------------------------------- var assignableRoles = CommonAction.IsSysAdmin(managerUserId) ? RoleDbAction.GetAllRols() : UserRolesDbAction.GetUserRolses(managerUserId).Where(n => !BuiltinRoles.Admins.Contains(n.RoleName)).ToList(); //------------------------------------- // 检索目标用户的已分配角色列表 //------------------------------------- var assignedRoles = targetUserId > 0 ? UserRolesDbAction.GetUserRolses(targetUserId) : DepartmentRolesDbAction.GetAssignedRolesOfDepartment(deparentmentId); //------------------------------------- // 已分配角色列表和可分配角色列表交叉运算 //------------------------------------- var response = assignableRoles.ConvertAll(a => { var resp = new RoleResponse() { RoleId = a.RoleId, RoleName = a.RoleName, Remark = a.Remark }; if (a.StartTime != null) { resp.StartTime = a.StartTime.Value.ToString("yyyy-MM-dd"); } if (a.EndTime != null) { resp.EndTime = a.EndTime.Value.ToString("yyyy-MM-dd"); } var index = assignedRoles.FindIndex(n => n.RoleId == resp.RoleId); if (index >= 0) { resp.IsChoice = true; assignedRoles.RemoveAt(index); } return(resp); }); if (assignedRoles.Count > 0) { response.InsertRange(0, assignedRoles.ConvertAll(a => { var resp = new RoleResponse() { RoleId = a.RoleId, RoleName = a.RoleName, Remark = a.Remark, IsChoice = true }; if (a.StartTime != null) { resp.StartTime = a.StartTime.Value.ToString("yyyy-MM-dd"); } if (a.EndTime != null) { resp.EndTime = a.EndTime.Value.ToString("yyyy-MM-dd"); } return(resp); })); } return(response.OrderBy(n => n.RoleName).ToList()); }