Skip to content

Instantly share code, notes, and snippets.

@grumpycatsaysno
Created July 7, 2017 13:58
Show Gist options
  • Save grumpycatsaysno/e55504377673b4a8bd62894344c61762 to your computer and use it in GitHub Desktop.
Save grumpycatsaysno/e55504377673b4a8bd62894344c61762 to your computer and use it in GitHub Desktop.
private IQueryable<BlogPost> FilterByCustomDateTimeCriteria(IQueryable<BlogPost> query, string sYear, string sMonth, ref int? totalCount)
{
var values = new List<object>();
var filterValues = new List<object>();
var years = sYear.Split(',');
var months = sMonth.Split(',');
//if the url does not contain a pair of month and year the query will not be filtered
if (years.Count() != months.Count())
{
return query;
}
string filter = null;
var j = 0;
var k = 1;
for (int i = 0; i < years.Count(); i++)
{
if (i > 0)
{
filter += "||";
++k;
j = k;
++k;
}
filter += this.SetDates(years[i], months[i], null, out values, "PublicationDate", j, k);
filterValues.AddRange(values);
}
if (filter == null)
{
return query;
}
query = query.Where(filter, filterValues.ToArray());
totalCount = query.Count();
return query;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment