I need to compare the value (key) of two Multinode Treepickers, and get a list of the nodes where the values are equal.
In my doctype I have a Multinode Treepicker with a list of members, and on my Member Profile I also have a Multinode Treepicker with members.
How can I make a foreach loop showing only theese nodes withe the same members as on my member profile?
My Member:
var profileModel = Members.GetCurrentMember();
var followings = profileModel.Value<IEnumerable<IPublishedContent>>("profileFollowings");
var followingsKeys = followings.Select(x => x.Key.ToString()).ToList();
My Doctype:
var items = Model.Children.Where(x => x.Value<IEnumerable<IPublishedContent>>("categoryItemRecommenders").Select(y => y.Key.ToString()).ToList().SequenceEqual(followingsKeys));
It does'nt quite work - items returns 0 - what am I missing...?
Hard to be sure without having the code in front of me, but are you basically trying to say, get me all the Category Item Recommenders who are ALSO in the current Logged in Member's profile followers?
And if so, would this be the sort of thing you are after:
var recommendersThatFollow = Model.Value<IEnumerable<IPublishedContent>>("categoryItemRecommenders").Where(f=>followingsKeys.Contains(f.Key.ToString()));
or have I misunderstood the content tree you are working with?
Hi Marc, you have understood my problem correct. I have allready tried your approach, but it does'nt work because it is two lists I'm comparring, not checking if my list contains a string. I can provide the whole code sample if it is needed...
\Robin :)
I think I may have misunderstood, then seeing the tree structure would help...
... I'm now thinking you have:
ThisPage
CategoryItemPage
CategoryItemPage
CategoryItemPage
CategoryItemPage
CategoryItemPage
And each 'CategoryItemPage' has the MemberPicker with alias 'categoryItemRecommenders'
So IF you are on the 'ThisPage', ALL the category pages would be accessible via:
var categoryItemPages = Model.Children();
But you only want the catetoryItemPages where the picker on the page includes any one of the picked members on the Current Member...
so I think it's really close to what you had before but something more like this:
var items = Model.Children.Where(x => x.Value<IEnumerable<IPublishedContent>>("categoryItemRecommenders").Select(y => y.Key.ToString()).Intersect(followingKeys).Any());
eg Get all the CategoryItemPage children where the picker's array of keys contains at least one match in the array of followingKeys.
Intersect will give you a new Array of all the matching elements in the two Arrays, and calling .Any() means the comparison will stop, just as soon as it finds 'one'!
Compare two Multinode Treepickers
I need to compare the value (key) of two Multinode Treepickers, and get a list of the nodes where the values are equal.
In my doctype I have a Multinode Treepicker with a list of members, and on my Member Profile I also have a Multinode Treepicker with members.
How can I make a foreach loop showing only theese nodes withe the same members as on my member profile?
My Member:
My Doctype:
It does'nt quite work - items returns 0 - what am I missing...?
Hi Robin
Hard to be sure without having the code in front of me, but are you basically trying to say, get me all the Category Item Recommenders who are ALSO in the current Logged in Member's profile followers?
And if so, would this be the sort of thing you are after:
or have I misunderstood the content tree you are working with?
regards
Marc
Hi Marc, you have understood my problem correct. I have allready tried your approach, but it does'nt work because it is two lists I'm comparring, not checking if my list contains a string. I can provide the whole code sample if it is needed... \Robin :)
Hi Robin
I think I may have misunderstood, then seeing the tree structure would help...
... I'm now thinking you have:
ThisPage
And each 'CategoryItemPage' has the MemberPicker with alias 'categoryItemRecommenders'
So IF you are on the 'ThisPage', ALL the category pages would be accessible via:
var categoryItemPages = Model.Children();
But you only want the catetoryItemPages where the picker on the page includes any one of the picked members on the Current Member...
so I think it's really close to what you had before but something more like this:
eg Get all the CategoryItemPage children where the picker's array of keys contains at least one match in the array of followingKeys.
Intersect will give you a new Array of all the matching elements in the two Arrays, and calling .Any() means the comparison will stop, just as soon as it finds 'one'!
well that's if' I've understood :-P
regards
Marc
Hi Marc, Your understanding was correct, and your code sample (with a little twist) helped me a lot...
This is how I ended up using it:
This sample gave me the desired result... H5y!
is working on a reply...