Exemplo n.º 1
0
 public FirstMenu(WebSysMenu web)
 {
     MenuName   = web.MenuName;
     MenuIcon   = web.MenuIcon;
     IndexCode  = web.IndexCode;
     MenuStatus = web.MenuStatus;
     MenuPid    = web.MenuPid;
     MenuSort   = web.MenuSort;
     MenuUrl    = web.MenuUrl;
 }
Exemplo n.º 2
0
        /// <summary>
        /// 子菜单页面
        /// </summary>
        /// <param name="menuid"></param>
        /// <returns></returns>
        public ActionResult MenuPageList(string menuid)
        {
            int        MenuId     = ConvertN.ToInt32(menuid);
            WebSysMenu CurMenu    = sysMenuManager.GetMenuById(MenuId);
            WebSysMenu ParentMenu = sysMenuManager.GetMenuById(CurMenu.MenuPid ?? 0);

            ViewBag.CurMenu    = CurMenu;
            ViewBag.ParentMenu = ParentMenu;
            return(View("~/WebManager/Views/WebSystem/MenuPageList.cshtml"));
        }
Exemplo n.º 3
0
 public AjaxResult <WebSysMenu> SaveMenu(WebSysMenu entity)
 {
     if (entity == null)
     {
         return(new AjaxResult <WebSysMenu>("请求数据无效!"));
     }
     if (string.IsNullOrEmpty(entity.MenuName))
     {
         return(new AjaxResult <WebSysMenu>("请输入栏目名称!"));
     }
     using (var scope = new TransactionScope())
     {
         int        r;
         WebSysMenu old = SaveMenu(entity, out r);
         if (r <= 0)
         {
             return(new AjaxResult <WebSysMenu>("更新失败"));
         }
         scope.Complete();
         return(new AjaxResult <WebSysMenu>(old));
     }
 }
Exemplo n.º 4
0
        public AjaxResult <dynamic> GetMenuEntity(int MenuID)
        {
            var menu = db.WebSysMenu.FirstOrDefault(m => m.MenuId == MenuID);

            if (menu == null)
            {
                menu = new WebSysMenu()
                {
                    MenuPid    = 0,
                    MenuStatus = 1
                }
            }
            ;
            var topMenus = db.WebSysMenu.Where(m => m.MenuId != MenuID && m.MenuPid == 0).ToList();
            var result   = new
            {
                menu     = menu,
                topMenus = topMenus
            };

            return(new AjaxResult <dynamic>(result));
        }
Exemplo n.º 5
0
        /// <summary>
        /// 删除菜单 及 用户权限的内的菜单ID
        /// </summary>
        /// <param name="Id">二级菜单ID</param>
        /// <returns></returns>
        public AjaxResult <object> DelSubmenu(long Id)
        {
            if (Id < 1)
            {
                return(new AjaxResult <Object>("请选择您要删除的菜单!"));
            }
            List <string> list   = new List <string>(); //所有删除的主菜单
            List <string> li_sub = new List <string>(); //所有删除的子菜单
            //删除菜单
            WebSysMenu menu = db.WebSysMenu.Where(w => w.MenuId == Id).FirstOrDefault();

            if (menu != null)
            {
                list.Add(menu.MenuId.ToString());
                //删除主菜单
                db.WebSysMenu.Remove(menu);


                //删除所有子菜单
                List <WebSysMenuPage> list_sub = db.WebSysMenuPage.Where(w => w.MenuId == Id).ToList();
                foreach (var sub in list_sub)
                {
                    li_sub.Add(sub.PageId.ToString());
                    db.WebSysMenuPage.Remove(sub);
                }
                //db.WebSysMenuPage.RemoveRange(list_sub);


                //递归调用
                //DelSubmenu(menu.MenuId);

                List <WebSysMenu> list_model = db.WebSysMenu.Where(w => w.MenuPid == menu.MenuId).ToList();
                foreach (var item in list_model)
                {
                    DelSubmenu(item.MenuId);
                }
            }

            //删除用户权限内的菜单ID
            List <WebSysRoleMenu> list_menu = db.WebSysRoleMenu.Where(w => w.MenuId == Id).ToList();//所有权限数据

            foreach (var item in list_menu)
            {
                //从权限表删除主菜单
                foreach (var me in list)
                {
                    if (me == item.MenuId.ToString())
                    {
                        db.WebSysRoleMenu.Remove(item);
                    }
                }


                //从权限表删除子菜单
                if (!string.IsNullOrWhiteSpace(item.PageIds))
                {
                    string[] PageIds = item.PageIds.Split(',');
                    var      cc      = PageIds.Where(w => !li_sub.Contains(w)).ToList();
                    item.PageIds = "";
                    cc.ForEach(str =>
                    {
                        if (item.PageIds != "")
                        {
                            item.PageIds += ",";
                        }
                        item.PageIds += str;
                    });
                }
            }
            db.SaveChanges();

            return(new AjaxResult <Object>("删除完成!", 0));
        }
Exemplo n.º 6
0
        public int MakeMenu2(List <MenuItemAttribute> allMenus)
        {
            int r = 0;

            //先进行排序
            allMenus = allMenus.OrderBy(m => m.IsMain).ToList();

            using (TransactionScope trans = new TransactionScope())
            {
                var           DBTopMenu   = db.WebSysMenu.Where(m => m.MenuPid == 0).ToList();
                List <string> ModuleNames = allMenus.Select(m => m.ModuleName).Distinct().ToList();
                foreach (var item in ModuleNames)
                {
                    var dbModule = DBTopMenu.FirstOrDefault(m => m.MenuName == item);
                    if (dbModule == null)
                    {
                        dbModule = new WebSysMenu()
                        {
                            CreateTime    = DateTime.Now,
                            IndexCode     = "",
                            MenuIcon      = "cogs",
                            MenuItempages = "",
                            MenuName      = item,
                            MenuPid       = 0,
                            MenuSort      = 0,
                            MenuStatus    = 1,
                            MenuUrl       = "",
                            UpdateTime    = DateTime.Now,
                        };
                        db.WebSysMenu.Add(dbModule);
                        r += db.SaveChanges();
                        dbModule.IndexCode = dbModule.MenuId.ToString("00000");
                        r += db.SaveChanges();
                    }
                }
                var DBAllMenus = db.WebSysMenu.ToList();
                var DBAllPages = db.WebSysMenuPage.ToList();
                foreach (var item in allMenus)
                {
                    var topMenu = DBAllMenus.Where(m => m.MenuName == item.ModuleName).FirstOrDefault();
                    var dbMenu  = DBAllMenus.FirstOrDefault(m => m.MenuUrl == item.Url);
                    if (dbMenu == null)
                    {
                        dbMenu = new WebSysMenu()
                        {
                            CreateTime    = DateTime.Now,
                            IndexCode     = "",
                            MenuIcon      = "",
                            MenuItempages = "",
                            MenuName      = item.IsMain == 1 ? item.MainName : item.SubName,
                            MenuPid       = topMenu.MenuId,
                            MenuSort      = 0,
                            MenuStatus    = 1,
                            MenuUrl       = item.Url,
                            UpdateTime    = DateTime.Now,
                        };
                        db.WebSysMenu.Add(dbMenu);
                    }
                    else
                    {
                        dbMenu.MenuName   = item.MainName;
                        dbMenu.MenuPid    = topMenu.MenuId;
                        dbMenu.UpdateTime = DateTime.Now;
                    }
                    r += db.SaveChanges();
                    dbMenu.IndexCode = topMenu.IndexCode + dbMenu.MenuId.ToString("00000");
                    r += db.SaveChanges();

                    foreach (var itemSub in item.SubPages)
                    {
                        var    itemPage    = DBAllPages.Where(m => m.PageUrl == itemSub.Url).FirstOrDefault();
                        string itemSubName = itemSub.IsMain == 1 ? itemSub.MainName : itemSub.SubName;
                        if (itemPage == null)
                        {
                            itemPage = new WebSysMenuPage()
                            {
                                CreateTime    = DateTime.Now,
                                MainStatus    = itemSub.IsMain == 1 ? 1 : 0,
                                MenuId        = dbMenu.MenuId,
                                PageBtnname   = itemSubName,
                                PageName      = itemSubName,
                                PageParamters = "",
                                PageStatus    = 1,
                                PageType      = itemSub.ReturnType == "JsonResult" ? 2 : 1,
                                PageUrl       = itemSub.Url,
                                PageViewname  = itemSubName,
                                UpdateTime    = DateTime.Now,
                            };
                            db.WebSysMenuPage.Add(itemPage);
                        }
                        else
                        {
                            itemPage.CreateTime   = DateTime.Now;
                            itemPage.MainStatus   = itemSub.IsMain == 1 ? 1 : 0;
                            itemPage.MenuId       = dbMenu.MenuId;
                            itemPage.PageBtnname  = itemSubName;
                            itemPage.PageName     = itemSubName;
                            itemPage.PageType     = itemSub.ReturnType == "JsonResult" ? 2 : 1;
                            itemPage.PageViewname = itemSubName;
                            itemPage.UpdateTime   = DateTime.Now;
                        }
                        r += db.SaveChanges();
                    }
                }
                trans.Complete();
                return(r);
            }
        }
Exemplo n.º 7
0
        private WebSysMenu SaveMenu(WebSysMenu entity, out int r)
        {
            r = 0;
            DateTime dtNow = DateTime.Now;
            var      old   = db.WebSysMenu.FirstOrDefault(m => m.MenuId == entity.MenuId);

            if (old == null)
            {
                old            = Newtonsoft.Json.JsonConvert.DeserializeObject <WebSysMenu>(Newtonsoft.Json.JsonConvert.SerializeObject(entity));
                old.CreateTime = dtNow;
                old.UpdateTime = dtNow;
                db.WebSysMenu.Add(old);
                r += db.SaveChanges();
            }
            else
            {
                old.MenuName      = entity.MenuName;
                old.MenuPid       = entity.MenuPid;
                old.MenuIcon      = entity.MenuIcon;
                old.MenuUrl       = entity.MenuUrl;
                old.MenuStatus    = entity.MenuStatus;
                old.MenuItempages = "";
                old.UpdateTime    = dtNow;
                old.MenuSort      = entity.MenuSort;
                r += db.SaveChanges();
            }
            string pIndexCode = "";

            if (entity.MenuPid != 0)
            {
                var pMenu = db.WebSysMenu.FirstOrDefault(m => m.MenuId == old.MenuPid);
                if (pMenu != null)
                {
                    pIndexCode = pMenu.IndexCode;
                }
            }
            old.IndexCode = pIndexCode + old.MenuId.ToString("00000");
            if (!string.IsNullOrWhiteSpace(entity.IndexCode))
            {
                old.IndexCode = entity.IndexCode;
            }
            r += db.SaveChanges();
            if (old.MenuPid != 0)
            {
                var menuPage = db.WebSysMenuPage.FirstOrDefault(m => m.MainStatus == 1 && m.MenuId == old.MenuId);
                if (menuPage == null)
                {
                    menuPage = new WebSysMenuPage()
                    {
                        CreateTime    = dtNow,
                        MainStatus    = 1,
                        MenuId        = old.MenuId,
                        PageBtnname   = old.MenuName,
                        PageName      = old.MenuName,
                        PageParamters = "",
                        PageStatus    = 1,
                        PageType      = 1,
                        PageUrl       = old.MenuUrl,
                        PageViewname  = old.MenuName,
                        UpdateTime    = dtNow,
                    };
                    db.WebSysMenuPage.Add(menuPage);
                    r += db.SaveChanges();
                }
                else
                {
                    menuPage.PageName     = old.MenuName;
                    menuPage.PageViewname = old.MenuName;
                    menuPage.PageUrl      = old.MenuUrl;
                    menuPage.UpdateTime   = dtNow;
                    r += db.SaveChanges();
                }
            }
            return(old);
        }
Exemplo n.º 8
0
        public JsonResult MenuSave(WebSysMenu entity)
        {
            var result = sysMenuManager.SaveMenu(entity);

            return(Json(result));
        }