Beispiel #1
0
        public static string PrepareMenu(List <NccMenuItem> menuItem, string currentLanguage, string upperSubMenuCls = "nav navbar-nav", string menuItemCls = "")
        {
            var user        = GlobalContext.GetCurrentUser();
            var subMenuText = "";

            menuItem = menuItem.OrderBy(m => m.MenuOrder).ToList();

            foreach (var item in menuItem)
            {
                var addItem = false;

                if (item.IsAnonymous)
                {
                    addItem = true;
                }
                else if (ControllerActionCache.ControllerActions.Where(x => x.MainController == item.Controller && x.MainAction == item.Action && x.ModuleName == item.Module).Count() > 0)
                {
                    if (user != null)
                    {
                        if (item.IsAllowAuthenticated || user.Roles.Where(x => x.Role.Name.Equals(NccCmsRoles.SuperAdmin)).Count() > 0)
                        {
                            addItem = true;
                        }
                        else
                        {
                            if (string.IsNullOrEmpty(item.Module))
                            {
                                if (user.ExtraDenies.Where(x => string.IsNullOrEmpty(x.ModuleName) && x.Controller == item.Controller && x.Action == item.Action).Count() == 0)
                                {
                                    if (user.Permissions.Where(x => x.Permission.PermissionDetails.Where(y => string.IsNullOrEmpty(y.ModuleName) && y.Controller == item.Controller && y.Action == item.Action).Count() > 0).Count() > 0)
                                    {
                                        addItem = true;
                                    }
                                    else if (user.ExtraPermissions.Where(x => string.IsNullOrEmpty(x.ModuleName) && x.Controller == item.Controller && x.Action == item.Action).Count() > 0)
                                    {
                                        addItem = true;
                                    }
                                }
                            }
                            else
                            {
                                if (user.ExtraDenies.Where(x => x.ModuleName == item.Module && x.Controller == item.Controller && x.Action == item.Action).Count() == 0)
                                {
                                    if (user.Permissions.Where(x => x.Permission.PermissionDetails.Where(y => y.ModuleName == item.Module && y.Controller == item.Controller && y.Action == item.Action).Count() > 0).Count() > 0)
                                    {
                                        addItem = true;
                                    }
                                    else if (user.ExtraPermissions.Where(x => x.ModuleName == item.Module && x.Controller == item.Controller && x.Action == item.Action).Count() > 0)
                                    {
                                        addItem = true;
                                    }
                                }
                            }
                        }
                    }
                }
                else
                {
                    addItem = true;
                }

                if (addItem)
                {
                    var hasChildren = item.Childrens.Count > 0;
                    if (hasChildren)
                    {
                        subMenuText = "<li class=\"" + menuItemCls + "\">";

                        if (!string.IsNullOrEmpty(currentLanguage) && GlobalContext.WebSite.IsMultiLangual && !IsExternalUrl(item.Url))
                        {
                            subMenuText += "<a href=\"/" + currentLanguage + item.Url + "\" class=\"dropdown-toggle\" data-toggle=\"dropdown\" > " + item.Name + "</a>";
                        }
                        else
                        {
                            subMenuText += "<a href=\"" + item.Url + "\" class=\"dropdown-toggle\" data-toggle=\"dropdown\" > " + item.Name + "</a>";
                        }

                        subMenuText += PrepareMenu(item.Childrens, currentLanguage, "dropdown-menu multi-level", "dropdown-submenu");
                        subMenuText += "</li>";
                    }
                    else
                    {
                        subMenuText += ListItemHtml(item, currentLanguage);
                    }
                }
            }

            var menuTxt = "";

            if (string.IsNullOrEmpty(subMenuText) == false)
            {
                menuTxt  = "<ul class=\"" + upperSubMenuCls + "\">";
                menuTxt += subMenuText;
                menuTxt += "</ul>";
            }

            return(menuTxt);
        }
Beispiel #2
0
 public NccUser GetCurrentUser()
 {
     return(GlobalContext.GetCurrentUser());
 }