コード例 #1
0
        /// <summary>
        /// 权限界面显示
        /// </summary>
        /// <returns></returns>
        public ActionResult ConfigPre()
        {
            List <Model.ModelViews.MainPage_View> pageList = new List <Model.ModelViews.MainPage_View>();
            var queryparentList = pageSer.QueryWhere(p => p.ParentID == 0);

            foreach (var item in queryparentList)
            {
                var res = pageSer.QueryWhere(p => p.ParentID == item.ID);
                Model.ModelViews.MainPage_View view = new Model.ModelViews.MainPage_View()
                {
                    childPage = res,
                    Page      = item
                };
                pageList.Add(view);
            }
            Model.VO.AuthorityPage_VO authorityPage = new Model.VO.AuthorityPage_VO();
            authorityPage.SysRole  = sysroleSer.QueryWhere();
            authorityPage.viewList = pageList;
            return(View(authorityPage));
        }
コード例 #2
0
        public object RolePage(int Roleid, int page, int limit, string showname)
        {
            //角色表
            var role = roledal.QueryWhere();
            //角色权限表
            var rolepageres    = dal.QueryWhere(d => d.SysRoleID == Roleid);
            var allrolepageres = dal.QueryWhere(p => p.SysRoleID == Roleid);
            //权限表
            var pageres = pagedal.QueryWhere();

            if (showname != null)
            {
                var pageid = pagedal.QueryWhere(p => p.ShowName.Contains(showname)).ToList();
                if (pageid.Count() > 0)
                {
                    List <int?> arr = new List <int?>();
                    foreach (var item in pageid)
                    {
                        arr.Add(item.ID);
                    }
                    rolepageres = rolepageres.Where(r => arr.Contains(r.PageID));
                }
                else
                {
                    rolepageres = rolepageres.Where(p => p.PageID == 0);
                }
            }
            //角色联表角色权限表
            var tt = role.Join(rolepageres.OrderBy(o => o.ID).Skip((page - 1) * limit).Take(limit).Join(pageres, m => m.PageID, n => n.ID, (m, n) => new
            {
                m.SysRoleID,
                n.ShowName,
                n.ID,
                n.ParentID
            }).OrderBy(o => o.ID), r => r.ID, aa => aa.SysRoleID, (r, aa) => new
                               { sysid = aa.SysRoleID,
                                 rolename = r.Name,
                                 pagename = aa.ShowName,
                                 pageid   = aa.ID,
                                 parentid = aa.ParentID }).ToList();
            var count   = rolepageres.Count();
            var tranres = new
            {
                code  = 0,
                msg   = "success",
                data  = tt,
                count = count
            };

            return(tranres);
        }
コード例 #3
0
        public object RoleUser(int Roleid, int page, int limit, string account)
        {
            try
            {
                //人员表
                var userres = userdal.QueryWhere();
                //角色表
                var roleres = roledal.QueryWhere();
                //角色人员表
                var res    = dal.QueryWhere(d => d.SysRoleID == Roleid);
                var allres = dal.QueryWhere(d => d.SysRoleID == Roleid);
                if (account != null)
                {
                    var          userid = userres.Where(u => u.Account.Contains(account)).ToList();
                    List <Guid?> arr    = new List <Guid?>();
                    if (userid.Count() > 0)
                    {
                        foreach (var item in userid)
                        {
                            arr.Add(item.ID);
                        }
                        res = res.Where(d => arr.Contains(d.UserID));
                    }
                    else
                    {
                        res = res.Where(d => d.UserID == null);
                    }
                }
                //通过角色id查出对应角色用户表
                var tt = res.OrderBy(o => o.ID).Skip((page - 1) * limit).Take(limit).Join(userres, m => m.UserID, n => n.ID, (m, n) => new { m.SysRoleID, rname = n.Name, n.Account, m.UserID }).ToList();

                List <Model.ViewObject.RoleUser_VO> listmodel = new List <Model.ViewObject.RoleUser_VO>();

                foreach (var item in tt)
                {
                    var roleall = roleres.Join(dal.QueryWhere(d => d.UserID == item.UserID), m => m.ID, n => n.SysRoleID, (m, n) => new
                    {
                        m.Name
                    }).ToList();
                    var str = "";
                    if (roleall.Count() > 0)
                    {
                        foreach (var it in roleall)
                        {
                            str += it.Name + ";";
                        }
                        Model.ViewObject.RoleUser_VO model = new Model.ViewObject.RoleUser_VO()
                        {
                            Name    = item.rname,
                            Account = item.Account,
                            AllRole = str
                        };
                        listmodel.Add(model);
                    }
                }

                var Count   = res.Count();
                var tranres = new
                {
                    code  = 0,
                    msg   = "success",
                    data  = listmodel,
                    count = Count
                };
                return(tranres);
            }catch (Exception e)
            {
                throw new Exception(e.Message);
            }
        }