Exemplo n.º 1
0
        private void AddOrUpdate(IEnumerable <MenuDefinition> definitions)
        {
            foreach (MenuDefinition definition in definitions)
            {
                Menu menu = _menuRepository.FirstOrDefault(t => t.Name == definition.Name);
                menu             = menu ?? new Menu();
                menu.DisplayName = definition.DisplayName;
                menu.MetaData    = definition.MetaData;
                menu.Icon        = definition.Icon;
                menu.Url         = definition.Url;
                menu.ParentId    = definition.ParentId;
                menu.Name        = definition.Name;
                menu.IsStatic    = true;

                if (menu.Id == default(int))
                {
                    var defaultactive = _settingManager.GetSettingValueForApplication <bool>(YtSettings.General.MenuDefaultActive);
                    menu.IsActive = defaultactive;
                    _levelEntityHandler.Create(menu);
                }
                else
                {
                    if (menu.ParentId == definition.ParentId)
                    {
                        _levelEntityHandler.Update(menu);
                    }
                    else
                    {
                        _levelEntityHandler.UpdateParent(menu);
                    }
                }
                //插入子集
                if (!definition.Childs.Any())
                {
                    continue;
                }
                foreach (var t in definition.Childs)
                {
                    t.ParentId = menu.Id;
                }
                AddOrUpdate(definition.Childs);
            }
        }
Exemplo n.º 2
0
 private void AddOrUpdate(IEnumerable <PermissionDefinition> definitions)
 {
     foreach (var definition in definitions)
     {
         var menu = _permissionRepository.FirstOrDefault(t => t.Name == definition.Name);
         menu                = menu ?? new YtPermission();
         menu.DisplayName    = definition.DisplayName;
         menu.Name           = definition.Name;
         menu.ParentId       = definition.ParentId;
         menu.Name           = definition.Name;
         menu.PermissionType = definition.PermissionType;
         menu.IsStatic       = true;
         if (menu.Id == default(int))
         {
             var defaultactive = _settingManager.GetSettingValueForApplication <bool>(YtSettings.General.PermissionDefaultActive);
             menu.IsActive = defaultactive;
             _levelEntityHandler.Create(menu);
         }
         else
         {
             if (menu.ParentId == definition.ParentId)
             {
                 _levelEntityHandler.Update(menu);
             }
             else
             {
                 _levelEntityHandler.UpdateParent(menu);
             }
         }
         //插入子集
         if (!definition.Children.Any())
         {
             continue;
         }
         foreach (var t in definition.Children)
         {
             t.ParentId = menu.Id;
         }
         AddOrUpdate(definition.Children);
     }
 }
        private void AddOrUpdate(IEnumerable <PermissionDefinition> definitions)
        {
            foreach (var definition in definitions)
            {
                var per = _permissionRepository.FirstOrDefault(t => t.Name == definition.Name);
                per                = per ?? new YtPermission();
                per.DisplayName    = definition.DisplayName;
                per.Name           = definition.Name;
                per.ParentId       = definition.ParentId;
                per.Name           = definition.Name;
                per.PermissionType = definition.PermissionType;
                per.IsStatic       = true;
                if (per.Id == default(int))
                {
                    per.IsActive = true;
                    _levelEntityHandler.Create(per);
                }
                else
                {
                    if (per.ParentId == definition.ParentId)
                    {
                        _levelEntityHandler.UpdateAsync(per);
                    }
                    else
                    {
                        _levelEntityHandler.UpdateParent(per);
                    }
                }

                //插入子集
                if (!definition.Childs.Any())
                {
                    continue;
                }
                foreach (var t in definition.Childs)
                {
                    t.ParentId = per.Id;
                }
                AddOrUpdate(definition.Childs);
            }
        }
Exemplo n.º 4
0
        private void AddOrUpdate(IEnumerable <MenuDefinition> definitions)
        {
            foreach (MenuDefinition definition in definitions)
            {
                Menu menu = _menuRepository.FirstOrDefault(t => t.Name == definition.Name);
                menu                        = menu ?? new Menu();
                menu.DisplayName            = definition.DisplayName;
                menu.MetaData               = definition.MetaData;
                menu.Icon                   = definition.Icon;
                menu.Url                    = definition.Url;
                menu.ParentId               = definition.ParentId;
                menu.Name                   = definition.Name;
                menu.RequiredPermissions    = definition.RequiredPermissions;
                menu.RequiresAuthentication = definition.RequiresAuthentication;
                menu.IsStatic               = true;
                menu.IsActive               = true;

                if (menu.Id == default(int))
                {
                    _levelEntityHandler.Create(menu);
                }
                else
                {
                    _levelEntityHandler.UpdateAsync(menu);
                }

                //插入子集
                if (!definition.Childs.Any())
                {
                    continue;
                }
                foreach (var t in definition.Childs)
                {
                    t.ParentId = menu.Id;
                }
                AddOrUpdate(definition.Childs);
            }
        }