Skip to content

Commit

Permalink
add support for sorting datetime, enum, and bool
Browse files Browse the repository at this point in the history
  • Loading branch information
crucelplayground committed Mar 12, 2020
1 parent 3fa09f7 commit 719a965
Show file tree
Hide file tree
Showing 5 changed files with 123 additions and 95 deletions.
17 changes: 12 additions & 5 deletions businessLogic/viewModels/genericCollectionItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,23 @@ public static ICollectionItem buildFromDbInstance(TDbItem _TDbItem)
number = dbPersistance.extentionHelpers.typeExtentions.getPagedListPropertyAttribute(item).getPosition(),
};

var _item = item.GetValue(_TDbItem);
var _itemValue = item.GetValue(_TDbItem);

if(_item is IPocoEntity _iPocoItem)
if(_itemValue != null)
{
_collectionItemProperty.value = _iPocoItem.name + " :: id: " + _iPocoItem.Id;
if (_itemValue is IPocoEntity _iPocoItem)
{
_collectionItemProperty.value = _iPocoItem.name + " :: id: " + _iPocoItem.Id;
}
else
{
_collectionItemProperty.value = _itemValue.ToString();
}
}
else
{
_collectionItemProperty.value = _item.ToString();
}
_collectionItemProperty.value = string.Empty;
}


_basicListCollectionItem.properties.Add(_collectionItemProperty);
Expand Down
23 changes: 22 additions & 1 deletion dbPersistance/extentionHelpers/expressionTreeBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,28 @@ public static Expression<Func<TDataItem, bool>> buildQueryExpression(string prop
}
throw new InvalidOperationException("provided expression can not be processes as it is of incorrect type...");

default:
case queryOptions.isTrue:

var isTrueParameter = Expression.Parameter(typeof(TDataItem), "w");
var isTrueProperty = Expression.Property(isTrueParameter, propertyName);
var isTruePropertyType = typeof(TDataItem).GetProperty(propertyName).PropertyType;

equalsBody = Expression.Equal(isTrueProperty,
Expression.Convert(Expression.Constant(true), isTruePropertyType));
var resultingLmbd = Expression.Lambda<Func<TDataItem, bool>>(equalsBody, isTrueParameter);
return resultingLmbd;

case queryOptions.isFalse:

var isFalseParameter = Expression.Parameter(typeof(TDataItem), "w");
var isFalseProperty = Expression.Property(isFalseParameter, propertyName);
var isFalsePropertyType = typeof(TDataItem).GetProperty(propertyName).PropertyType;

equalsBody = Expression.Equal(isFalseProperty,
Expression.Convert(Expression.Constant(false), isFalsePropertyType));
return Expression.Lambda<Func<TDataItem, bool>>(equalsBody, isFalseParameter);

default:
return null;
}
#endregion
Expand Down
10 changes: 5 additions & 5 deletions genericPagingSortingClean/Web.config
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,15 @@
</dependentAssembly>
</assemblyBinding>
</runtime>
<entityFramework>
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
</providers>
</entityFramework>
<system.codedom>
<compilers>
<compiler language="c#;cs;csharp" extension=".cs" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:default /nowarn:1659;1699;1701" />
<compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:default /nowarn:41008 /define:_MYTYPE=\&quot;Web\&quot; /optionInfer+" />
</compilers>
</system.codedom>
<entityFramework>
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
</providers>
</entityFramework>
</configuration>
4 changes: 2 additions & 2 deletions genericPagingSortingClean/genericPagingSortingClean.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project ToolsVersion="15.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.2.0.1\build\net46\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props" Condition="Exists('..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.2.0.1\build\net46\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props')" />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\TypeScript\Microsoft.TypeScript.Default.props" Condition="Exists('$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\TypeScript\Microsoft.TypeScript.Default.props')" />
<Import Project="..\packages\EntityFramework.6.4.0\build\EntityFramework.props" Condition="Exists('..\packages\EntityFramework.6.4.0\build\EntityFramework.props')" />
<Import Project="..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.2.0.1\build\net46\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props" Condition="Exists('..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.2.0.1\build\net46\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props')" />
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
Expand Down Expand Up @@ -367,9 +367,9 @@
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.2.0.1\build\net46\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.2.0.1\build\net46\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props'))" />
<Error Condition="!Exists('..\packages\EntityFramework.6.4.0\build\EntityFramework.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\EntityFramework.6.4.0\build\EntityFramework.props'))" />
<Error Condition="!Exists('..\packages\EntityFramework.6.4.0\build\EntityFramework.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\EntityFramework.6.4.0\build\EntityFramework.targets'))" />
<Error Condition="!Exists('..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.2.0.1\build\net46\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.2.0.1\build\net46\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props'))" />
</Target>
<Import Project="..\packages\EntityFramework.6.4.0\build\EntityFramework.targets" Condition="Exists('..\packages\EntityFramework.6.4.0\build\EntityFramework.targets')" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Expand Down
164 changes: 82 additions & 82 deletions testSandBox/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,88 +13,88 @@ class Program
{
static void Main(string[] args)
{
//Random rnd = new Random();

//int startValue = 0;
//int maxValue = 0;

//while (maxValue <= 100000)
//{
// Console.WriteLine("processing nex badge");

// if (maxValue > 0)
// {
// startValue = maxValue;
// }

// maxValue = startValue + 1000;

// using (unitOfWork<dbItemTypeOne> unit = new unitOfWork<dbItemTypeOne>())
// {

// for (int i = startValue; i < maxValue; i++)
// {
// unit.repository.Insert(new dbItemTypeOne()
// {
// guid = Guid.NewGuid().ToString(),
// name = rnd.Next(1, 100000) + "-name-" + rnd.Next(1, 100000),
// decimalData = rnd.Next(1, 100000),
// description = rnd.Next(1, 100000) + "descripiton - " + rnd.Next(1, 100000),
// boolvalue = getBoolValue(rnd.Next(1, 100000))
// });

// Console.WriteLine("processing item #: " + i);
// }

// unit.Save();
// }

// using (unitOfWork<dbItemTypeTwo> unit = new unitOfWork<dbItemTypeTwo>())
// {

// for (int i = startValue; i < maxValue; i++)
// {
// unit.repository.Insert(new dbItemTypeTwo()
// {
// guid = Guid.NewGuid().ToString(),
// name = rnd.Next(1, 100000) + "-name-" + rnd.Next(1, 100000),
// decValue = rnd.Next(1, 100000),
// description = rnd.Next(1, 100000) + "descripiton - " + rnd.Next(1, 100000),
// stringValueOne = rnd.Next(1, 100000) + " - stringValueOne - " + rnd.Next(1, 100000),
// stringValueTwo = rnd.Next(1, 100000) + " - stringValueTwo - " + rnd.Next(1, 100000),
// intVlue = rnd.Next(1, 100000),
// invFieldTwo = rnd.Next(1, 100000)
// });

// Console.WriteLine("processing item #: " + i);
// }

// unit.Save();
// }

// DateTime start = new DateTime(1995, 1, 1);
// int range = (DateTime.Today - start).Days;

// using (unitOfWork<dbItemTypeThree> unit = new unitOfWork<dbItemTypeThree>())
// {

// for (int i = startValue; i < maxValue; i++)
// {
// unit.repository.Insert(new dbItemTypeThree()
// {
// guid = Guid.NewGuid().ToString(),
// name = rnd.Next(1, 100000) + "-name-" + rnd.Next(1, 100000),
// description = rnd.Next(1, 100000) + "descripiton - " + rnd.Next(1, 100000),
// dataTypeEnum = (dataTypeEnum)rnd.Next(0, 3),
// indicatedDate = start.AddDays(rnd.Next(range))
// });

// Console.WriteLine("processing item #: " + i);
// }

// unit.Save();
// }
//}
Random rnd = new Random();

int startValue = 0;
int maxValue = 0;

while (maxValue <= 100000)
{
Console.WriteLine("processing nex badge");

if (maxValue > 0)
{
startValue = maxValue;
}

maxValue = startValue + 1000;

using (unitOfWork<dbItemTypeOne> unit = new unitOfWork<dbItemTypeOne>())
{

for (int i = startValue; i < maxValue; i++)
{
unit.repository.Insert(new dbItemTypeOne()
{
guid = Guid.NewGuid().ToString(),
name = rnd.Next(1, 100000) + "-name-" + rnd.Next(1, 100000),
decimalData = rnd.Next(1, 100000),
description = rnd.Next(1, 100000) + "descripiton - " + rnd.Next(1, 100000),
boolvalue = getBoolValue(rnd.Next(1, 100000))
});

Console.WriteLine("processing item #: " + i);
}

unit.Save();
}

using (unitOfWork<dbItemTypeTwo> unit = new unitOfWork<dbItemTypeTwo>())
{

for (int i = startValue; i < maxValue; i++)
{
unit.repository.Insert(new dbItemTypeTwo()
{
guid = Guid.NewGuid().ToString(),
name = rnd.Next(1, 100000) + "-name-" + rnd.Next(1, 100000),
decValue = rnd.Next(1, 100000),
description = rnd.Next(1, 100000) + "descripiton - " + rnd.Next(1, 100000),
stringValueOne = rnd.Next(1, 100000) + " - stringValueOne - " + rnd.Next(1, 100000),
stringValueTwo = rnd.Next(1, 100000) + " - stringValueTwo - " + rnd.Next(1, 100000),
intVlue = rnd.Next(1, 100000),
invFieldTwo = rnd.Next(1, 100000)
});

Console.WriteLine("processing item #: " + i);
}

unit.Save();
}

DateTime start = new DateTime(1995, 1, 1);
int range = (DateTime.Today - start).Days;

using (unitOfWork<dbItemTypeThree> unit = new unitOfWork<dbItemTypeThree>())
{

for (int i = startValue; i < maxValue; i++)
{
unit.repository.Insert(new dbItemTypeThree()
{
guid = Guid.NewGuid().ToString(),
name = rnd.Next(1, 100000) + "-name-" + rnd.Next(1, 100000),
description = rnd.Next(1, 100000) + "descripiton - " + rnd.Next(1, 100000),
dataTypeEnum = (dataTypeEnum)rnd.Next(0, 3),
indicatedDate = start.AddDays(rnd.Next(range))
});

Console.WriteLine("processing item #: " + i);
}

unit.Save();
}
}

linkItems();
}
Expand Down

0 comments on commit 719a965

Please sign in to comment.