Exclude items from autocomplete method
I have the following code that pulls off a list of items used in an text box autocomplete extender:
return autocomplete.tblAutoCompletes
.Where(p => p.MemberId == memberid && p.LocationId == locationid && p.ACItem.Contains(prefixText))
.OrderBy(p => p.ACItem)
.Select(p => p.ACItem)
.Take(count)
.ToArray();
Where memberid and locationid are sessions.
Within this list of items, I have some that I may wish to exclude depending upon user preferences. This preference also being stored as a session.
So for example I开发者_Go百科 have the following table:
ACItem ACColumn
aa Product
ab Product
ac Product
ad Status
ae Status
af Status
ag Category
ai Category
aj Category
The if I typed in "a" into my text box, all products ACItems would be displayed.
However, there may be a scenario whereby I don't want a users autocomplete to display a certain status and or product. For example, I don't want the user to see the status "af" or category "ai".
I have these preferences stored as a session when the user logs in (i.e. "DoNotDisplayaf" or "DoNotDisplayai")
How do I amend my original method so that the autocomplete takes these exceptions into account?
Apologies for being thick and if my question/example is a little hazy.
Thank you for any help received.
Not quite sure I follow, but given you do not want all product categories to be shown, wouldn't you be able to filter these out in the Where clause of your linq query?
.Where(p => p.MemberId == memberid
&& p.LocationId == locationid
&& p.ACItem.Contains(prefixText)
&& shouldBeDisplayed(p))
ShouldBeDisplayed is a function that checks the given item with the conditions in your session state to tell if they should be shown or not.
精彩评论