Skip to content
This repository has been archived by the owner on Sep 11, 2019. It is now read-only.

Commit

Permalink
Fix issue with Date and filters
Browse files Browse the repository at this point in the history
  • Loading branch information
geoperez committed Jul 20, 2015
1 parent 5393ff8 commit 5247dda
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 27 deletions.
50 changes: 25 additions & 25 deletions Unosquare.Tubular/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -148,23 +148,6 @@ public static GridDataResponse CreateGridDataResponse(this GridDataRequest reque
return response;
}

// TODO: This code is for use with Dynamic LINQ, but It needs EF
//private static bool isDynamicLinqReady = false;

//private static void FixDynamicLinq()
//{
// var type = typeof(DynamicQueryable).Assembly.GetType("System.Linq.Dynamic.ExpressionParser");

// FieldInfo field = type.GetField("predefinedTypes", BindingFlags.Static | BindingFlags.NonPublic);

// Type[] predefinedTypes = (Type[])field.GetValue(null);

// Array.Resize(ref predefinedTypes, predefinedTypes.Length + 1);
// predefinedTypes[predefinedTypes.Length - 1] = typeof(EntityFunctions); // Your type

// field.SetValue(null, predefinedTypes);
//}

private static string GetSqlOperator(CompareOperators op)
{
switch (op)
Expand Down Expand Up @@ -217,11 +200,21 @@ private static IQueryable FilterResponse(GridDataRequest request, IQueryable sub
case CompareOperators.NotEquals:
if (String.IsNullOrWhiteSpace(column.Filter.Text)) continue;

// TODO: This code is for use with Dynamic LINQ, but It needs EF
//if (column.DataType == DataType.Date.ToString().ToLower())
// searchLambda.AppendFormat("EntityFunctions.TruncateTime({0}) == @{1} &&", column.Name, searchParamArgs.Count);
//else
searchLambda.AppendFormat("{0} {2} @{1} &&", column.Name, searchParamArgs.Count, GetSqlOperator(column.Filter.Operator));
if (column.DataType == DataType.Date.ToString().ToLower())
{
if (column.Filter.Operator == CompareOperators.Equals)
{
searchLambda.AppendFormat("({0} >= @{1} && {0} <= @{2}) &&", column.Name, searchParamArgs.Count, searchParamArgs.Count + 1);
}
else
{
searchLambda.AppendFormat("({0} < @{1} || {0} > @{2}) &&", column.Name, searchParamArgs.Count, searchParamArgs.Count + 1);
}
}
else
{
searchLambda.AppendFormat("{0} {2} @{1} &&", column.Name, searchParamArgs.Count, GetSqlOperator(column.Filter.Operator));
}

if (String.Equals(column.DataType, DataType.Numeric.ToString(),
StringComparison.CurrentCultureIgnoreCase))
Expand All @@ -230,12 +223,19 @@ private static IQueryable FilterResponse(GridDataRequest request, IQueryable sub
}
else if (
String.Equals(column.DataType, DataType.DateTime.ToString(),
StringComparison.CurrentCultureIgnoreCase) ||
String.Equals(column.DataType, DataType.Date.ToString(), StringComparison.CurrentCultureIgnoreCase))
StringComparison.CurrentCultureIgnoreCase))
{
searchParamArgs.Add(DateTime.Parse(column.Filter.Text));
}
else if (String.Equals(column.DataType, DataType.Boolean.ToString(), StringComparison.CurrentCultureIgnoreCase))
else if (
String.Equals(column.DataType, DataType.Date.ToString(),
StringComparison.CurrentCultureIgnoreCase))
{
searchParamArgs.Add(DateTime.Parse(column.Filter.Text).Date);
searchParamArgs.Add(DateTime.Parse(column.Filter.Text).Date.AddDays(1).AddMinutes(-1));
}
else if (String.Equals(column.DataType, DataType.Boolean.ToString(),
StringComparison.CurrentCultureIgnoreCase))
{
searchParamArgs.Add(Boolean.Parse(column.Filter.Text));
}
Expand Down
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "tubular",
"version": "0.9.20",
"version": "0.9.21",
"description": "A set of AngularJS directives and designed to rapidly build modern web applications.",
"homepage": "http://unosquare.github.io/tubular",
"repository": {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "tubular",
"filename": "tubular-bundle.min.js",
"version": "0.9.20",
"version": "0.9.21",
"description": "A set of AngularJS directives and designed to rapidly build modern web applications.",
"repository": {
"type": "git",
Expand Down

0 comments on commit 5247dda

Please sign in to comment.