Exemplo n.º 1
0
        public ActionResult Admin_menu()
        {
            StringBuilder strData         = new StringBuilder();
            UserModels    userModels      = new UserModels();
            var           admin_menu_view = new Admin_menu_view();

            using (var data = new Entities())
            {
                List <C_UserPage> lstParent = userModels.GetListParentPage();
                if (lstParent.Any())
                {
                    strData.Append(" <ul class=\"nav nav-list\">");
                    foreach (var parent in lstParent)
                    {
                        List <C_UserPage> lstChild = userModels.GetListUserPageByParrentID(parent.id);
                        bool          isAdd        = false;
                        StringBuilder menuChild    = new StringBuilder();
                        if (lstChild.Any())
                        {
                            menuChild.Append("<ul class=\"submenu\">");
                            foreach (var child in lstChild)
                            {
                                string url = Url.RouteUrl("admin_default", new { controller = "dashboard", action = "index", act = child.act, ctrl = child.ctrl, type_act = child.TypeAction, type = child.Tye, page = "1", parent = "0" });
                                if (UserModels.CheckPermission(this.Session["mem"] != null ? this.Session["mem"].ToString() : string.Empty, child.act, child.ctrl, child.TypeAction, child.Tye))
                                {
                                    menuChild.Append("<li><a href=\"" + url + "\">" + child.Icon + "</i>" + child.Title + "</a></li>");
                                    isAdd = true;
                                }
                            }

                            menuChild.Append("</ul>");
                        }

                        if (isAdd)
                        {
                            strData.Append("<li>");
                            strData.Append(" <a href=\"#\" class=\"dropdown-toggle\">" + parent.Icon + "<span class=\"menu-text\">" + parent.Title + "</span><b class=\"arrow icon-angle-down\"></b></a>");
                            strData.Append(menuChild);
                            strData.Append("</li>");
                        }
                    }

                    strData.Append("</ul>");
                }
            }

            admin_menu_view.Menu = strData.ToString();

            return(this.PartialView("../control/admin_menu", admin_menu_view));
        }
Exemplo n.º 2
0
        public IActionResult Get()
        {
            var identity = (ClaimsIdentity)User.Identity;
            IEnumerable <Claim> claims = identity.Claims;
            var userLogin = claims.FirstOrDefault(c => c.Type == ClaimTypes.Email).Value;

            UserModels       userModels = new UserModels();
            List <AdminMenu> adminMenu  = new List <AdminMenu>();
            List <UserPage>  lstParent  = userModels.GetListParentPage();

            if (lstParent.Any())
            {
                foreach (var parent in lstParent)
                {
                    AdminMenu menuItem = new AdminMenu();
                    menuItem.title       = parent.Title;
                    menuItem.icon        = parent.Icon;
                    menuItem.link        = parent.Path;
                    menuItem.type        = parent.Tye;
                    menuItem.home        = parent.Path == "dashboard" ? true : false;
                    menuItem.group       = false;
                    menuItem.queryParams = string.Empty;

                    List <UserPage>  lstChild  = userModels.GetListUserPageByParrentID(parent.Id);
                    bool             isChild   = false;
                    List <AdminMenu> menuChild = new List <AdminMenu>();
                    if (lstChild.Any())
                    {
                        foreach (var child in lstChild)
                        {
                            var isShow = UserModels.CheckPermissionMenu(userLogin, (string.IsNullOrEmpty(child.Path) ? string.Empty : child.Path), child.Tye);
                            if (isShow)
                            {
                                var path = string.Empty;
                                if (!string.IsNullOrEmpty(child.Path))
                                {
                                    path = child.Path;
                                }

                                AdminMenu menuItemChild = new AdminMenu
                                {
                                    title       = child.Title,
                                    icon        = child.Icon,
                                    link        = path,
                                    type        = child.Tye,
                                    home        = false,
                                    group       = false,
                                    queryParams = string.Empty
                                };
                                menuChild.Add(menuItemChild);
                                isChild = true;
                            }
                        }
                    }

                    if (isChild)
                    {
                        menuItem.children = menuChild;
                        adminMenu.Add(menuItem);
                    }
                }
            }

            return(Json(adminMenu));
        }