Click here to Skip to main content
15,891,033 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Ok i have a ICollection<tasks> which i wish to filter and return filtered tasks.

i have many filters some dependant on others, works like this

If user selects CreatedBy, AssignedTo and UpdatedBy - a User filter is then required to be chosen

the user can also select the following filters:

Priority,TaskType, TaskStatus, Date,

at the moment the filter values are taken using Javascript and passed to my Controller into a ViewModel, which the filtering logic is done and the the filtered Collection Returned to view.

Now i need help building the filtering logic, what is the most concise way of filtering the collection, taking into account that some of the filters may not be selected and therefore ALL should be returned under that category.

Thanks
Posted
Comments
DamithSL 11-Dec-14 11:54am    
update the question with your method which you going to handle the filtering with your current code
Grant Weatherston 12-Dec-14 3:12am    
i dont have any current code, this is why i have asked for the help as i don't know how to do it

You might be interested in Invent your own Dynamic LINQ parser[^].

Cheers
Andi
 
Share this answer
 
Comments
Maciej Los 14-Dec-14 12:55pm    
+5
Andreas Gieriet 14-Dec-14 14:24pm    
Thanks for your 5!
Cheers
Andi
I'd suggest to start with basics: How to: Query a Collection of Objects (C# Programming Guide)[^]. It's quite simple. Try! If you get stuck, then come back here and ask detailed question.

Tutorial: Asp.NET MVC3 And LinQ Based Sample Web Application[^]
 
Share this answer
 
Comments
Andreas Gieriet 14-Dec-14 14:24pm    
Good links! My 5!
Cheers
Andi
Maciej Los 14-Dec-14 14:46pm    
Thank you, Andi ;)
[EDIT]
By The Way: I don't see your 5 ;(
i utilised Linq in the end using following code:
C#
var results = from t in db.IT_Tasks
                          where (

                                  ((model.UserFilterTypeID == 0) || (model.UserFilterTypeID == 1 && t.CreatedByID == model.UserID)
|| (model.UserFilterTypeID == 2 && t.AssignedUserID == model.UserID)|| (model.UserFilterTypeID == 3 && t.UpdatedByID == model.UserID))&& (model.TaskStatusID == 0 || t.TaskStatusID == model.TaskStatusID)&& (model.TaskTypeID == 0 || t.TaskTypeID == model.TaskTypeID)&& ((model.DateTypeID == 0)|| (model.DateTypeID == 1 && t.DateCreated >= model.DateFrom && t.DateCreated <=model.DateTo )|| (model.DateTypeID==2 && t.DateUpdated >= model.DateFrom && t.DateUpdated <= model.DateTo))
                           )
                          select t;
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900