private static void AddSubRoles(List<Role> availableRoles, RoleEntity entity) { if (entity.ChildRoleIds != null) { foreach (var roleId in entity.ChildRoleIds) { RoleEntity roleEntity = GenericRepository.GetItemTopById<RoleEntity>(AuthAdminDatabase, RolesCollection, roleId); if (roleEntity != null && roleEntity.DateTimeDeleted == DateTime.MinValue) { availableRoles.Add(roleEntity.TranslateToResponse()); AddSubRoles(availableRoles, roleEntity); } } } }
private void AddAvailableRoles(List<Role> availableRoles, RoleEntity entity, int id, int parentId) { if (entity.ChildRoleIds != null) { foreach (var roleId in entity.ChildRoleIds) { RoleEntity roleEntity = GenericRepository.GetItemTopById<RoleEntity>(AuthAdminDatabase, RolesCollection, roleId); if (roleEntity != null && roleEntity.DateTimeDeleted == DateTime.MinValue) { // Do not add moving role or its parent to the list if(roleEntity.Id != id && roleEntity.Id != parentId) availableRoles.Add(roleEntity.TranslateToResponse()); AddAvailableRoles(availableRoles, roleEntity, id, parentId); } } } }
private void SetTreeItem(TreeItem treeItem, RoleEntity entity) { treeItem.Id = entity.Id; treeItem.Label = entity.Label; treeItem.RootParentId = entity.RootParentId; treeItem.ParentId = entity.ParentId; treeItem.Children = new List<TreeItem>(); if (entity.ChildRoleIds != null) { treeItem.Children = new List<TreeItem>(); foreach (var roleId in entity.ChildRoleIds) { RoleEntity roleEntity = GenericRepository.GetItemTopById<RoleEntity>(AuthAdminDatabase, RolesCollection, roleId); if (roleEntity != null && roleEntity.DateTimeDeleted == DateTime.MinValue) { TreeItem item = new TreeItem(); SetTreeItem(item, roleEntity); treeItem.Children.Add(item); } } } }