Dim listePreFiltree As List(Of FamilleProduitModel) = listeFPA.FindAll(Function(f) f.Libelle.ToUpper().Contains(texteRecherche) OrElse
f.ListProduit.Any(Function(p) p.Libelle.ToUpper().Contains(texteRecherche)) OrElse
f.ListProduit.Any(Function(p) p.ListArticle.Any(Function(a) a.Libelle.ToUpper().Contains(texteRecherche)))).ToList()
' Une fois les données préfiltrées, on va supprimer les éléments en bout de chaîne qui ne contiennent pas le texte recherché.
Dim listeArtSuppr As New List(Of ArticleModel)
Dim listeProdSuppr As New List(Of ProduitModel)
For Each fam As FamilleProduitModel In listePreFiltree
For Each prod As ProduitModel In fam.ListProduit
For Each art As ArticleModel In prod.ListArticle
If Not art.Libelle.ToUpper().Contains(texteRecherche) Then
listeArtSuppr.Add(art)
End If
Next
For Each element In listeArtSuppr
prod.ListArticle.Remove(element)
Next
listeArtSuppr.Clear()
If Not prod.Libelle.ToUpper().Contains(texteRecherche) AndAlso prod.ListArticle.Count = 0 Then
listeProdSuppr.Add(prod)
End If
Next
For Each element In listeProdSuppr
fam.ListProduit.Remove(element)
Next
listeProdSuppr.Clear()
Next
Return listePreFiltree
Partager