Exemplo n.º 1
0
        public void Execute(BasePage Context)
        {
            TemplateFormat xf = new TemplateFormat(Context);

            QueryParam qp = new QueryParam();

            qp.ReturnFields = "ID,Title";


            qp.PageIndex = WebHelper.GetIntParam(Context.Request, "PageIndex", 1);
            qp.PageSize  = WebHelper.GetIntParam(Context.Request, "PageSize", xf.ViewSettingT <Int32>("General.Search.Size", 10));


            var RoleGroupList = RoleController.GetRoleGroups(Context.PortalId);
            var RoleGroups    = Common.Split <RoleGroupInfo>(RoleGroupList, 1, 999);

            String SearchText = WebHelper.GetStringParam(Context.Request, "search", "");

            if (!String.IsNullOrEmpty(SearchText))
            {
                RoleGroups = RoleGroups.FindAll(r => r.RoleGroupName.IndexOf(SearchText, StringComparison.CurrentCultureIgnoreCase) >= 0);
            }

            RoleGroups = Common.Split <RoleGroupInfo>(RoleGroups, qp.PageIndex, qp.PageSize);



            Dictionary <String, Object> jsonPictures = new Dictionary <string, Object>();


            JavaScriptSerializer jsSerializer = new JavaScriptSerializer();

            List <Dictionary <String, Object> > DictItems = new List <Dictionary <string, object> >();

            foreach (var RoleGroupItem in RoleGroups)
            {
                int index = RoleGroups.IndexOf(RoleGroupItem); //index 为索引值

                Dictionary <String, Object> jsonDict = new Dictionary <String, Object>();

                jsonDict.Add("id", RoleGroupItem.RoleGroupID);
                jsonDict.Add("text", RoleGroupItem.RoleGroupName);

                jsonDict.Add("roles", Playngo_ClientZone_RoleGroup.FindRolesByGroup(Context.PortalId, RoleGroupItem.RoleGroupID));
                DictItems.Add(jsonDict);
            }

            jsonPictures.Add("Items", DictItems);
            jsonPictures.Add("Pages", qp.Pages);
            jsonPictures.Add("RecordCount", RoleGroupList.Count);

            //转换数据为json
            ResponseString = jsSerializer.Serialize(jsonPictures);
        }
        /// <summary>
        /// 获取用户列表
        /// </summary>
        /// <returns></returns>
        public List <UserInfo> GetUserList()
        {
            int RecordCount = 0;

            var   UserList    = new List <UserInfo>();
            Int32 RoleGroupId = WebHelper.GetIntParam(Request, ddlRoleGroups.UniqueID, -1);

            if (RoleGroupId >= 0)
            {
                var Roles = Playngo_ClientZone_RoleGroup.FindRolesByGroup(PortalId, RoleGroupId);
                if (Roles != null && Roles.Count > 0)
                {
                    foreach (var role in Roles)
                    {
                        var RoleUsers = RoleController.Instance.GetUsersByRole(PortalId, role.RoleName);
                        if (RoleUsers != null && RoleUsers.Count > 0)
                        {
                            foreach (var RoleUser in RoleUsers)
                            {
                                if (!UserList.Exists(r => r.UserID == RoleUser.UserID))
                                {
                                    UserList.Add(RoleUser);
                                }
                            }
                        }
                    }
                }
                else
                {
                    //该分组下没有任何角色
                }
            }
            else
            {
                //没有选择任何角色
                //UserList = Common.Split<UserInfo>(UserController.GetUsers(PortalId, 0, 999, ref RecordCount), 1, 9999);
            }

            return(UserList);
        }
Exemplo n.º 3
0
        /// <summary>
        /// 设置角色和用户的关系
        /// </summary>
        /// <returns>返回已经添加的角色</returns>
        private List <String> SetDataItem(ref UserInfo UserItem)
        {
            Int32 SelectUserID = WebHelper.GetIntParam(Request, "ddlSelectUser", 0);

            String SelectRoleGroups     = String.Empty;
            String SelectRoleGroupTexts = String.Empty;

            WebHelper.GetSelected(cblRoleGroups, out SelectRoleGroupTexts, out SelectRoleGroups);


            List <String> AddRoleStatus = new List <string>();

            if (SelectUserID > 0)
            {
                if (!String.IsNullOrEmpty(SelectRoleGroups))
                {
                    List <String> RoleGroupIDs = Common.Split <String>(Common.GetList(SelectRoleGroups), 1, 9999);
                    if (RoleGroupIDs != null && RoleGroupIDs.Count > 0)
                    {
                        //取出用户信息
                        UserItem = UserController.GetUserById(PortalId, SelectUserID);
                        if (UserItem != null && UserItem.UserID > 0)
                        {
                            //整理出来需要添加的分组
                            var Roles = new List <RoleInfo>();
                            foreach (var strRoleGroupID in RoleGroupIDs)
                            {
                                Int32 RoleGroupID = 0;
                                if (Int32.TryParse(strRoleGroupID, out RoleGroupID) && RoleGroupID >= 0)
                                {
                                    //取出角色分组信息
                                    Roles.AddRange(Playngo_ClientZone_RoleGroup.FindRolesByGroup(PortalId, RoleGroupID));
                                }
                            }

                            //对比用户的角色,将需要添加的角色关系添加好
                            if (Roles != null && Roles.Count > 0)
                            {
                                foreach (var role in Roles)
                                {
                                    //不存在的角色才需要添加
                                    if (!UserItem.IsInRole(role.RoleName))
                                    {
                                        RoleController.Instance.AddUserRole(PortalId, UserItem.UserID, role.RoleID, RoleStatus.Approved, false, xUserTime.LocalTime(), xUserTime.LocalTime().AddYears(100));
                                        AddRoleStatus.Add(role.RoleName);
                                    }
                                }
                            }
                            else
                            {
                                //没有需要添加的角色
                                XTrace.WriteLine("没有需要添加的角色");
                            }
                        }
                        else
                        {
                            //选择的用户无法查找到信息
                            XTrace.WriteLine("选择的用户无法查找到信息");
                        }
                    }
                    else
                    {
                        //角色分组信息解析有问题
                        XTrace.WriteLine("角色分组信息解析有问题");
                    }
                }
                else
                {
                    //未选择角色分组
                    XTrace.WriteLine("未选择角色分组");
                }
            }
            else
            {
                //未选择用户
                XTrace.WriteLine("未选择用户");
            }

            return(AddRoleStatus);
        }