/// <summary> /// Updates the <see cref="FilterOptions"/> for the user's currently selected project, for the view provided by the key parameter. /// This checks and uses querystring values for the <see cref="FilterOptions"/> values. /// </summary> protected void UpdateUserFilterOptions(string key) { if (!string.IsNullOrEmpty(Request.QueryString["title"]) || !string.IsNullOrEmpty(Request.QueryString["startDate"]) || !string.IsNullOrEmpty(Request.QueryString["endDate"]) || !string.IsNullOrEmpty(Request.QueryString["assignedTo"]) || !string.IsNullOrEmpty(Request.QueryString["status"]) ) { FilterOptions filterOptions = FilterOptions.Parse(Request.QueryString["title"], Request.QueryString["assignedTo"], Request.QueryString["startDate"], Request.QueryString["endDate"], Request.QueryString["status"]); ProjectFilterOptions project = UserContext.Current.Settings.GetFilterOptionsForProject(UserContext.Current.CurrentProject.Name); project.UpdateFilterOption(key, filterOptions); } }
public static IQueryable <Project> ApplyFilterOption(this IQueryable <Project> projectsQuery, ProjectFilterOptions option, string filterValue) { if (string.IsNullOrEmpty(filterValue) || option == ProjectFilterOptions.Default) { return(projectsQuery); } switch (option) { case ProjectFilterOptions.ByDeadline: DateTime date; try { date = DateTime.Parse(filterValue); Console.WriteLine("Date is: " + date.Date.ToString()); } catch (Exception ex) { Console.WriteLine(ex.Message); return(projectsQuery); } return(projectsQuery.Where(p => p.Deadline >= date)); case ProjectFilterOptions.ByName: Console.WriteLine("Applying name filter"); return(projectsQuery.Where(p => p.Name.Contains(filterValue))); case ProjectFilterOptions.ByDescription: return(projectsQuery.Where(p => p.Description.Contains(filterValue))); case ProjectFilterOptions.ByOwner: return(projectsQuery.Where(p => p.ProjectUsersReq .Where(pur => pur.Role.RoleName == "PROJECT_MANAGER") .FirstOrDefault() .UserAssigned.UserName == filterValue)); default: return(projectsQuery); } }