Пример #1
0
 public static AuthorityService instance()
 {
     if (_instance == null)
     {
         _instance = new AuthorityService();
     }
     return(_instance);
 }
Пример #2
0
        public IEnumerable <Role> GetEnumByID(Guid id)
        {
            IEnumerable <Role> result = new List <Role>();

            _db.Execute(() =>
            {
                result = _db.GetList <Role>(m => m.ID == id);
            });
            result.Each(m => m.Item_Authoritys = AuthorityService.instance().GetAuthorityListByRole(m.ID));
            return(result);
        }
Пример #3
0
        public MenuService(Guid uid)
        {
            //权限菜单
            user = UserService.instance().GetEntityByID(uid);
            IEnumerable <Role> roles      = RoleService.instance().GetEnumByUID(uid);
            List <Authority>   Authoritys = new List <Authority>();
            List <Menu>        menus      = new List <Menu>();

            foreach (var item in roles)
            {
                Authoritys.AddRange(AuthorityService.instance().GetAuthorityListByRole(item.ID));
            }
            foreach (var item in Authoritys.GroupBy(m => new { m.PID }))
            {
                Menu menu = new Menu();
                menu.Name   = item.First().ParentAuth.Name;
                menu.Icon   = "";
                menu.URL    = "";
                menu.Type   = 1;
                menu.Childs = new List <Menu>();
                var xx = item.OrderBy(m => m.Sort);
                foreach (var auth in xx)
                {
                    menu.Childs.Add(new Menu()
                    {
                        Name = auth.Name,
                        URL  = auth.Description,
                        Icon = ""
                    });
                }
                menus.Add(menu);
            }



            //功能菜单
            IEnumerable <Class> classs = ClassService.instance().GetChildByID(Guid.Empty, user.CompanyID).OrderBy(m => m.Sort);

            foreach (var cl in classs)
            {
                Menu menu = new Menu();
                menu.Name   = cl.Title;
                menu.Type   = cl.Type;
                menu.Childs = new List <Menu>();
                menu.ID     = cl.ID;
                if (cl.Ishaschild)
                {
                    menu.Type = 1;
                    menu.URL  = "#";
                    cl.Childs.Each(m =>
                    {
                        menu.Childs.Add(new Menu()
                        {
                            Name = m.Title,
                            Icon = "",
                            Type = m.Type,
                            ID   = m.ID
                        });
                    });
                }
                menus.Add(menu);
            }



            VelocityEngine vltEngine = new VelocityEngine();

            vltEngine.SetProperty(RuntimeConstants.RESOURCE_LOADER, "file");
            vltEngine.SetProperty(RuntimeConstants.FILE_RESOURCE_LOADER_PATH, AppDomain.CurrentDomain.BaseDirectory);
            vltEngine.Init();

            var vltContext = new VelocityContext();

            vltContext.Put("MENU", menus);
            Template vltTemplate = vltEngine.GetTemplate("_menu.vm");
            var      vltWriter   = new System.IO.StringWriter();

            vltTemplate.Merge(vltContext, vltWriter);
            this._html = vltWriter.GetStringBuilder().ToString();
        }