public ActionResult MenuDrag() { List <MenuDrag> Functions = new List <MenuDrag>(); List <DSRCManagementSystem.Models.MenuDrag> objmodel = new List <Models.MenuDrag>(); MenuDrag MainMenus = new MenuDrag(); MainMenus.Children = new List <MenuListItem>(); int userId = int.Parse(Session["UserID"].ToString()); var RoleID = db.UserRoles.Where(x => x.UserID == userId).Select(o => o.RoleID).FirstOrDefault(); MenuListItem MainMenu = new MenuListItem(); var temp = db.GetMenuListByClientIdRoleID(userId, RoleID).ToList(); MainMenu.Children = new List <MenuListItem>(); foreach (MenuListByClientIdRoleID menu in temp) { MenuListItem Function; MenuListItem Module; if (String.IsNullOrEmpty(menu.PageUrl)) { menu.PageUrl = "#"; } Function = MainMenu.Children.Where(x => x.MenuName.Equals(menu.FunctionName)).FirstOrDefault(); if (Function == null) { Function = new MenuListItem() { MenuName = menu.FunctionName, MenuIcon = menu.ModuleIcon, Children = new List <MenuListItem>() } } ; if (String.IsNullOrEmpty(menu.ModuleName)) { Function.Url = menu.PageUrl; Function.Children = null; } else { Function.Url = "javascript:;"; Module = Function.Children.Where(x => x.MenuName.Equals(menu.ModuleName)).FirstOrDefault(); if (Module == null) { Module = new MenuListItem() { MenuName = menu.ModuleName, MenuIcon = menu.SubModuleIcon, Children = new List <MenuListItem>() } } ; if (String.IsNullOrEmpty(menu.SubModuleName)) { Module.Url = menu.PageUrl; Module.Children = null; } else { Module.Url = "javascript:;"; Module.Children.Add(new MenuListItem() { MenuName = menu.SubModuleName, MenuIcon = menu.SubMenuIcon, Url = menu.PageUrl, Children = null }); } if (Function.Children.Where(x => x.MenuName.Equals(Module.MenuName)).FirstOrDefault() == null) { Function.Children.Add(Module); } } if (MainMenu.Children.Where(x => x.MenuName.Equals(Function.MenuName)).FirstOrDefault() == null) { MainMenu.Children.Add(Function); MainMenus.Children.Add(Function); } } var FunctionName = new List <string>(); List <string> Value = new List <string>(); foreach (var x in MainMenus.Children) { DSRCManagementSystem.Models.MenuDrag ob = new DSRCManagementSystem.Models.MenuDrag(); var Function = x.MenuName; ob.FunctionName = Function; var id = db.Functions.Where(o => o.FunctionName == Function).Select(a => a.FunctionID).FirstOrDefault(); ob.FunctionID = id; objmodel.Add(ob); } return(View(objmodel)); }
public static MenuListItem GetUserMenu(int UserID, int RoleID) { MenuListItem MainMenu = new MenuListItem(); using (DSRCManagementSystemEntities1 db = new DSRCManagementSystemEntities1()) { var temp = db.GetMenuListByClientIdRoleID(UserID, RoleID).ToList(); MainMenu.Children = new List <MenuListItem>(); foreach (MenuListByClientIdRoleID menu in temp) { MenuListItem Function; MenuListItem Module; if (String.IsNullOrEmpty(menu.PageUrl)) { menu.PageUrl = "#"; } Function = MainMenu.Children.Where(x => x.MenuName.Equals(menu.FunctionName)).FirstOrDefault(); if (Function == null) { Function = new MenuListItem() { MenuName = menu.FunctionName, MenuIcon = menu.ModuleIcon, Children = new List <MenuListItem>() } } ; if (String.IsNullOrEmpty(menu.ModuleName)) { Function.Url = menu.PageUrl; Function.Children = null; } else { Function.Url = "javascript:;"; Module = Function.Children.Where(x => x.MenuName.Equals(menu.ModuleName)).FirstOrDefault(); if (Module == null) { Module = new MenuListItem() { MenuName = menu.ModuleName, MenuIcon = menu.SubModuleIcon, Children = new List <MenuListItem>() } } ; if (String.IsNullOrEmpty(menu.SubModuleName)) { Module.Url = menu.PageUrl; Module.Children = null; } else { Module.Url = "javascript:;"; Module.Children.Add(new MenuListItem() { MenuName = menu.SubModuleName, MenuIcon = menu.SubMenuIcon, Url = menu.PageUrl, Children = null }); } if (Function.Children.Where(x => x.MenuName.Equals(Module.MenuName)).FirstOrDefault() == null) { Function.Children.Add(Module); } } if (MainMenu.Children.Where(x => x.MenuName.Equals(Function.MenuName)).FirstOrDefault() == null) { MainMenu.Children.Add(Function); } } } return(MainMenu); }