예제 #1
0
 public static ClassService instance()
 {
     if (_instance == null)
     {
         _instance = new ClassService();
     }
     return(_instance);
 }
예제 #2
0
        /// <summary>
        /// 根据公司ID获取值
        /// </summary>
        /// <param name="cid">公司ID</param>
        /// <returns></returns>
        public IEnumerable <Class> GetEnumByCID(Guid cid)
        {
            IEnumerable <Class> result = new List <Class>();

            _db.Execute(() =>
            {
                result = _db.GetList <Class>(m => m.CompanyID == cid && m.DR == false);
            });
            result.Each(m =>
            {
                m.CompanyName = CompanyService.instance().GetNameByID(m.CompanyID);
                m.Childs      = ClassService.instance().GetChildByID(m.ID, m.CompanyID);
            });
            return(result);
        }
예제 #3
0
        public News Single(Guid id)
        {
            News entity = new News();

            _db.Execute(() =>
            {
                entity = _db.Single <News>(m => m.ID == id);
            });
            if (entity != null)
            {
                entity.Count++;
                this.Update(entity);
            }
            entity.ClassName = ClassService.instance().Single(entity.ClassID).Title;
            return(entity);
        }
예제 #4
0
 /// <summary>
 /// 判断基本功能是否有权限
 /// </summary>
 /// <param name="cid">栏目ID</param>
 /// <param name="uid">用户ID</param>
 /// <returns></returns>
 public bool CheckRole_ClassID(Guid cid, Guid uid)
 {
     return(UserService.instance().GetEntityByID(uid).CompanyID.Equals(ClassService.instance().GetEnumByID(cid).FirstOrDefault().CompanyID));
 }
예제 #5
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();
        }