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);
            }
        }
Esempio n. 2
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);
            }
        }