Example #1
0
        private void ItemParse(XElement el, List<MenuItem> menuitems, MenuItem parent = null)
        {
            MenuItem mi = new MenuItem()
            {
                Parent = parent,
                Title = this.GetAttrValue(el, "title"),
                Mnemonic = this.GetAttrValue(el, "mnemonic"),
                Icon = this.GetAttrValue(el, "icon"),
                URL = this.GetAttrValue(el, "url")
            };

            var forSysRoleValue = this.GetAttrValue(el, "for-system-role");
            if (!string.IsNullOrWhiteSpace(forSysRoleValue))
            {
                SystemRole role;
                if (Enum.TryParse(forSysRoleValue, out role))
                {
                    mi.ForSystemRole = role;
                }
            }


            menuitems.Add(mi);

            foreach (XElement item in el.Elements())
            {
                this.ItemParse(item, mi.Items, mi);
            }
        }
Example #2
0
        private void InitAndFilterPermission(List<MenuItem> srcItems, List<MenuItem> destItems, MenuItem parent = null)
        {
            var securityUser = AppContext.SecurityUser;

            foreach (MenuItem sitem in srcItems.ToList())
            {
                MenuItem ditem = null;
                
                if (sitem.ForSystemRole == null || securityUser.IsSysRole(sitem.ForSystemRole.Value))
                {
                    if (!String.IsNullOrEmpty(sitem.Mnemonic))
                    {
                        var config = _viewModelConfigService.Get(sitem.Mnemonic);

                        if (securityUser.IsPermission(config.TypeEntity, TypePermission.Navigate))
                        {
                            ditem = ObjectHelper.CreateAndCopyObject<MenuItem>(sitem, new Type[] { typeof(MenuItem) });

                            if (String.IsNullOrEmpty(ditem.Title))
                            {
                                ditem.Title = config.ListView.Title;
                            }

                            if (String.IsNullOrEmpty(ditem.Icon))
                            {
                                ditem.Icon = config.Icon;
                            }
                        }
                    }
                    else
                    {
                        ditem = ObjectHelper.CreateAndCopyObject<MenuItem>(sitem, new Type[] { typeof(MenuItem) });
                    }

                    if (ditem != null)
                    {
                        destItems.Add(ditem);

                        InitAndFilterPermission(sitem.Items, ditem.Items, sitem);
                    }

                    if (ditem != null)
                    {
                        ditem.Parent = parent;
                    }
                }
            }
        }