Reputation: 2906
my use-case: I have 2 SPLists, let's call one events, the other attendees. What I want: Show a "register" or "unregister" button (in a visual web part at the dispform of the event-list) depending of the current User can be located in the attendee-list for the current event. So, if the current user is registered for the event, page_load should show the "unregister"-button or the "register"-button if he's not.
I get the current Item via
currEventItem = (SPListItem)SPContext.Current.Item;
And the current user via
currentUser = website.CurrentUser;
userString = currentUser.ID.ToString() + ";#" + currentUser.LoginName.ToString();
Now I wanted to use System.Linq (Linq to Objects) to execute the following Query (pseudo-sqlsyntax):
select * from AttendeeList where userString equals attendeeList.Name
AND currEventItem.Title equals AttendeeList.EventTitle
The Name-Field in the attendeeList is a user (person or group, using german version here so I hope this is the actual translation) field.
My Problem, and the actual question: I don't get the linq syntax to work. Could anyone help me out here? Would be great!
edit: Later on, I want to show the corresponding button depending on the result is NULL or not NULL. Hope this works? If this is not the way to go, another solution would be greatly appreciated :)
Upvotes: 1
Views: 956
Reputation: 5594
This will give you true or false which you can apply to your checkbox?:
Boolean exists = (AttendeeList.Where(m=> m.Name == userString)
.Where(m=> m.EventTitle == currEventItem.Title).Count() > 0);
Upvotes: 2