Skip to content

Commit

Permalink
added enumerable extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
suxrobGM committed Dec 8, 2023
1 parent 2be8102 commit d26e188
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 6 deletions.
19 changes: 14 additions & 5 deletions src/Core/Logistics.Domain/Extensions/EnumerableExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,20 @@

public static class EnumerableExtensions
{
public static IEnumerable<TSource> Sort<TSource>(
public static IOrderedEnumerable<TSource> OrderBy<TSource, TKey>(
this IEnumerable<TSource> query,
Func<TSource, object> keySelector,
bool descending)
Func<TSource, TKey> keySelector,
bool isDescendingOrder)
{
return descending ? query.OrderByDescending(keySelector) : query.OrderBy(keySelector);
return isDescendingOrder ? query.OrderByDescending(keySelector) : query.OrderBy(keySelector);
}
}

public static IEnumerable<TSource> ApplyPaging<TSource>(
this IEnumerable<TSource> query,
int page,
int pageSize)
{
return query.Skip((page - 1) * pageSize)
.Take(pageSize);
}
}
20 changes: 19 additions & 1 deletion src/Core/Logistics.Domain/Extensions/QueryableExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Logistics.Domain.Core;
using System.Linq.Expressions;
using Logistics.Domain.Core;
using Logistics.Domain.Specifications;

namespace Logistics.Domain.Persistence;
Expand Down Expand Up @@ -31,4 +32,21 @@ public static class QueryableExtensions

return query;
}

public static IQueryable<TSource> OrderBy<TSource, TKey>(
this IQueryable<TSource> query,
Expression<Func<TSource, TKey>> keySelector,
bool isDescendingOrder)
{
return isDescendingOrder ? query.OrderByDescending(keySelector) : query.OrderBy(keySelector);
}

public static IQueryable<TSource> ApplyPaging<TSource>(
this IQueryable<TSource> query,
int page,
int pageSize)
{
return query.Skip((page - 1) * pageSize)
.Take(pageSize);
}
}

0 comments on commit d26e188

Please sign in to comment.