Exemple #1
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));
        }