public ActionResult AddMenuPage(int id = 0)
        {
            T_SysMenus model = new T_SysMenus();

            if (id == 0)
            {
                model.Id       = 0;
                model.MenuName = "根节点";
            }
            else
            {
                model = SysMenusService.GetModel(x => x.ParentId == id).FirstOrDefault();
            }
            return(View(model));
        }
Exemplo n.º 2
0
        public ActionResult InitMenu()
        {
            var nodes = MvcSiteMapProvider.SiteMaps.Current.FindSiteMapNodeFromKey("root").ChildNodes;

            foreach (var node in nodes)
            {
                if (!node.Clickable)
                {
                    T_SysMenus menu = new T_SysMenus();
                    menu.Guid       = Guid.NewGuid().ToString("N");
                    menu.MenuName   = node.Title;
                    menu.MenuUrl    = "";
                    menu.ParentId   = 0;
                    menu.CreateTime = DateTime.Now;
                    menu.CreateUser = 1;
                    menu.IconFont   = (string)node.Attributes["iconfont"];
                    var result = SysMenuService.AddEntity(menu);
                    if (result.IsSuccess)
                    {
                        T_SysMenus        addMenu    = JsonConvert.DeserializeObject <T_SysMenus>(result.Data);
                        var               childNodes = node.ChildNodes;
                        List <T_SysMenus> menuList   = new List <T_SysMenus>();
                        foreach (var childNode in childNodes)
                        {
                            T_SysMenus menuNew = new T_SysMenus();
                            menuNew.Guid       = Guid.NewGuid().ToString("N");
                            menuNew.MenuName   = childNode.Title;
                            menuNew.MenuUrl    = "/" + childNode.Controller + "/" + childNode.Action;
                            menuNew.ParentId   = addMenu.Id;
                            menuNew.IsLeaf     = true;
                            menuNew.CreateTime = DateTime.Now;
                            menuNew.CreateUser = 1;
                            menuList.Add(menuNew);
                        }

                        var resultNew = SysMenuService.AddRange(menuList);
                    }
                }
            }
            return(null);
        }
        public ActionResult AddMenuNode(SysMenu sysMenu)
        {
            var result = SysMenusService.IsLackRuquiredMenuInfo(sysMenu);

            if (!result.IsSuccess)
            {
                return(Json(result));
            }
            result = SysMenusService.IsRepeatedMenuNameOrUrl(sysMenu.MenuName, sysMenu.MenuUrl);
            if (!result.IsSuccess)
            {
                return(Json(result));
            }
            T_SysMenus menu = Mapper.Map <T_SysMenus>(sysMenu);

            menu.Guid       = Guid.NewGuid().ToString("N");
            menu.IsDeleted  = false;
            menu.CreateUser = UserId;
            menu.CreateTime = DateTime.Now;
            result          = SysMenusService.Add(menu);
            return(Json(result));
        }
Exemplo n.º 4
0
        public ActionResult Test()
        {
            #region 初始化菜单

            SysMenuService.Clear(typeof(T_SysMenus).Name);

            var nodes = MvcSiteMapProvider.SiteMaps.Current.FindSiteMapNodeFromKey("root").ChildNodes;
            foreach (var node in nodes)
            {
                if (!node.Clickable)
                {
                    T_SysMenus menu = new T_SysMenus();
                    menu.Guid       = Guid.NewGuid().ToString("N");
                    menu.MenuName   = node.Title;
                    menu.MenuUrl    = "";
                    menu.ParentId   = 0;
                    menu.CreateTime = DateTime.Now;
                    menu.CreateUser = 1;
                    menu.IconFont   = (string)node.Attributes["iconfont"];
                    var result = SysMenuService.AddEntity(menu);
                    if (result.IsSuccess)
                    {
                        T_SysMenus        addMenu    = JsonConvert.DeserializeObject <T_SysMenus>(result.Data);
                        var               childNodes = node.ChildNodes;
                        List <T_SysMenus> menuList   = new List <T_SysMenus>();
                        foreach (var childNode in childNodes)
                        {
                            T_SysMenus menuNew = new T_SysMenus();
                            menuNew.Guid       = Guid.NewGuid().ToString("N");
                            menuNew.MenuName   = childNode.Title;
                            menuNew.MenuUrl    = "/" + childNode.Controller + "/" + childNode.Action;
                            menuNew.ParentId   = addMenu.Id;
                            menuNew.IsLeaf     = true;
                            menuNew.CreateTime = DateTime.Now;
                            menuNew.CreateUser = 1;
                            menuList.Add(menuNew);
                        }

                        var resultNew = SysMenuService.AddRange(menuList);
                    }
                }
            }

            #endregion

            #region 初始化权限操作列表

            List <T_SysOperations> list = new List <T_SysOperations>();

            //创建控制器类型列表
            List <Type> controllerTypes = new List <Type>();

            //加载程序集
            var assembly = Assembly.Load("AdminWeb");

            controllerTypes.AddRange(assembly.GetTypes().Where(type => typeof(Controller).IsAssignableFrom(type) & type.IsDefined(typeof(DescriptionAttribute))));

            foreach (var controller in controllerTypes)
            {
                //var controller = assembly.GetTypes().Where(type => type.Name == itemType.Name).FirstOrDefault();

                //获取控制器的标记属性
                var typeName = ((DescriptionAttribute)controller.GetCustomAttributes(typeof(DescriptionAttribute)).FirstOrDefault()).Name;

                //获取所有的标记方法
                var actions = controller.GetMethods().Where(method => method.IsDefined(typeof(DescriptionAttribute)));

                foreach (var action in actions)
                {
                    var             attr      = ((DescriptionAttribute)action.GetCustomAttributes(typeof(DescriptionAttribute)).FirstOrDefault()).Name;
                    var             isNotShow = ((DescriptionAttribute)action.GetCustomAttributes(typeof(DescriptionAttribute)).FirstOrDefault()).IsNotShow;
                    T_SysOperations model     = new T_SysOperations();
                    model.ContronllerName = controller.Name.Replace("Controller", "");
                    model.ActionName      = action.Name;
                    model.TypeName        = typeName;
                    model.OperateName     = attr;
                    model.Guid            = Guid.NewGuid().ToString("N");
                    model.CreateUser      = 1;
                    model.CreateTime      = DateTime.Now;
                    if (isNotShow)
                    {
                        model.IsNotShow = true;
                    }
                    list.Add(model);
                }
            }

            #endregion

            InitDataService.InitData(list);
            return(View());
        }
Exemplo n.º 5
0
        public ActionResult SysMenusSave(T_SysMenus menu, string operatype)
        {
            KeyValueModel ret = base.error_r;

            try
            {
                using (WechatEntities context = new WechatEntities())
                {
                    switch (operatype)
                    {
                        #region 新增
                    case "add":
                        if (context.T_SysMenus.Any(m => m.MenuId == menu.MenuId))
                        {
                            ret.Value = "已经存在菜单代码为" + menu.MenuId + "的菜单";
                        }
                        else
                        {
                            switch (menu.MenuLevel)
                            {
                            case 1:
                            case 2:
                                var cnt = context.T_SysMenus.Where(m => m.MenuLevel == menu.MenuLevel && m.IsDeleted == false);
                                menu.CreateTime = DateTime.Now;
                                context.T_SysMenus.Add(menu);
                                context.SaveChanges();
                                ret = base.success_r;
                                break;
                            }
                        }
                        break;

                        #endregion
                        #region 修改
                    case "modify":
                        T_SysMenus _menu = context.T_SysMenus.Where(m => m.MenuId == menu.MenuId && m.IsDeleted == false).FirstOrDefault();
                        if (_menu != null)
                        {
                            _menu.ModifyTime     = DateTime.Now;
                            _menu.SortNum        = menu.SortNum;
                            _menu.MenuName       = menu.MenuName;
                            _menu.ParentId       = menu.ParentId;
                            _menu.ParentMenuName = menu.ParentMenuName;
                            _menu.Islink         = menu.Islink;
                            _menu.MenuIcon       = menu.MenuIcon;
                            _menu.MenuUrl        = menu.MenuUrl;
                            context.SaveChanges();
                            ret = base.success_r;
                        }
                        else
                        {
                            ret.Value = "未能找到此菜单,可能已被删除!";
                        }

                        break;

                        #endregion
                        #region  除
                    case "delete":
                        T_SysMenus MN = context.T_SysMenus.Where(m => m.MenuId == menu.MenuId && m.IsDeleted == false).FirstOrDefault();
                        if (MN != null)
                        {
                            MN.IsDeleted  = true;
                            MN.ModifyTime = DateTime.Now;
                            context.SaveChanges();
                            ret = base.success_r;
                        }
                        break;
                        #endregion
                    }
                }
            }
            catch (Exception ex)
            {
                ret.Value = ex.Message;
            }

            return(Json(ret, JsonRequestBehavior.AllowGet));
        }