new ordering system added
This commit is contained in:
@@ -52,14 +52,18 @@ public abstract class QueryParameters
|
||||
|
||||
#region PRIVATE METHODS
|
||||
|
||||
protected static bool TestBoolean(bool property, bool? query) =>
|
||||
protected static bool Test<T>(T? property, T? query) =>
|
||||
(
|
||||
query is null
|
||||
||
|
||||
property == query
|
||||
(
|
||||
property is not null
|
||||
&&
|
||||
property.Equals(query)
|
||||
)
|
||||
);
|
||||
|
||||
protected static bool TestString(string? property, string? regexQuery) =>
|
||||
protected static bool TestStringWithRegex(string? property, string? regexQuery) =>
|
||||
(
|
||||
string.IsNullOrEmpty(regexQuery)
|
||||
||
|
||||
@@ -108,7 +112,7 @@ public abstract class QueryParameters
|
||||
|
||||
|
||||
|
||||
public abstract class QueryParameters<T> : QueryParameters where T : class
|
||||
public abstract class QueryParameters<T> : QueryParameters where T : IQueryOrderable<T>
|
||||
{
|
||||
#region PUBLIC METHODS
|
||||
|
||||
@@ -120,22 +124,9 @@ public abstract class QueryParameters<T> : QueryParameters where T : class
|
||||
|
||||
if (OrderBy is not null)
|
||||
{
|
||||
PropertyInfo[] properties = typeof(T).GetProperties();
|
||||
foreach (PropertyInfo property in properties)
|
||||
if (T.OrderableProperties.TryGetValue(OrderBy, out Func<T, IComparable>? orderFunc))
|
||||
{
|
||||
JsonPropertyNameAttribute? attribute = property.GetCustomAttributes<JsonPropertyNameAttribute>(true).FirstOrDefault();
|
||||
if (attribute is not null && attribute.Name == OrderBy)
|
||||
{
|
||||
if (Order == "asc")
|
||||
{
|
||||
data = data.OrderBy(property.GetValue);
|
||||
}
|
||||
else
|
||||
{
|
||||
data = data.OrderByDescending(property.GetValue);
|
||||
}
|
||||
break;
|
||||
}
|
||||
data = Order == "asc" ? data.OrderBy(orderFunc) : data.OrderByDescending(orderFunc);
|
||||
}
|
||||
}
|
||||
if (After is not null)
|
||||
|
||||
Reference in New Issue
Block a user