Skip to content

Commit

Permalink
chore: update launch settings and refactor sorting
Browse files Browse the repository at this point in the history
  • Loading branch information
gdenchevprog committed Nov 28, 2022
1 parent 1104afc commit 57b8749
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 13 deletions.
17 changes: 8 additions & 9 deletions core/KendoCoreService/Extensions/SortingExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@ public static IQueryable<T> Sort<T>(this IQueryable<T> data, List<Sort> sorts)

foreach (var sort in sorts)
{
var propInfo = CommonExtension.GetPropertyInfo(typeof(T), sort.Field);
var expr = ExpressionExtension.BuildLambda(typeof(T), propInfo);

string methodName = string.Empty;

if (isFirst)
Expand All @@ -32,21 +29,23 @@ public static IQueryable<T> Sort<T>(this IQueryable<T> data, List<Sort> sorts)
methodName = sort.Dir == "asc" ? "ThenBy" : "ThenByDescending";
}

var method = typeof(Queryable).GetMethods().FirstOrDefault(m => m.Name == methodName && m.GetParameters().Length == 2);
var genericMethod = method.MakeGenericMethod(typeof(T), propInfo.PropertyType);

data = (IQueryable<T>)genericMethod.Invoke(null, new object[] { data, expr });
data = data.ApplySort(methodName, sort.Field);
}

return data;
}

public static IQueryable<T> GroupSort<T>(this IQueryable<T> data, string dir)
{
var propInfo = CommonExtension.GetPropertyInfo(typeof(T), "Key");
var expr = ExpressionExtension.BuildLambda(typeof(T), propInfo);
var methodName = dir == "asc" ? "OrderBy" : "OrderByDescending";

return data.ApplySort(methodName, "Key");
}

private static IQueryable<T> ApplySort<T>(this IQueryable<T> data, string methodName, string field)
{
var propInfo = CommonExtension.GetPropertyInfo(typeof(T), field);
var expr = ExpressionExtension.BuildLambda(typeof(T), propInfo);

var method = typeof(Queryable).GetMethods().FirstOrDefault(m => m.Name == methodName && m.GetParameters().Length == 2);
var genericMethod = method.MakeGenericMethod(typeof(T), propInfo.PropertyType);
Expand Down
6 changes: 2 additions & 4 deletions core/KendoCoreService/Properties/launchSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,15 @@
"KendoCoreService": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"launchUrl": "weatherforecast",
"launchBrowser": false,
"applicationUrl": "https://localhost:7099;http://localhost:5099",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"launchUrl": "weatherforecast",
"launchBrowser": false,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
Expand Down

0 comments on commit 57b8749

Please sign in to comment.