Sieve/SieveUnitTests/Services/SieveCustomSortMethods.cs
Hasan a4509bb8f0
OrderByDynamic is modified to be able to handle inherited members, such as interface members.
SieveProcessor is modified to pass propertyInfo to OrderByDynamic to avoid reattainment of propertyInfo required in Expression.MakeMemberAccess.
SieveProcessor is modified to be able to handle possible multiple incompatible customMethods via AggregateException.
Corresponding interfaces are generated for entities with related inheritance.
ApplicationSieveProcessor is modified to include interface members.
SieveCustomFilterMethods and SieveCustomSortMethod are modified to include interface related custom method modifications.
Interface accessed unit tests are added.
2020-11-03 12:42:41 +03:00

42 lines
1.3 KiB
C#

using System.Linq;
using Sieve.Services;
using SieveUnitTests.Abstractions.Entity;
using SieveUnitTests.Entities;
namespace SieveUnitTests.Services
{
public class SieveCustomSortMethods : ISieveCustomSortMethods
{
public IQueryable<Post> Popularity(IQueryable<Post> source, bool useThenBy, bool desc)
{
var result = useThenBy ?
((IOrderedQueryable<Post>)source).ThenBy(p => p.LikeCount) :
source.OrderBy(p => p.LikeCount)
.ThenBy(p => p.CommentCount)
.ThenBy(p => p.DateCreated);
return result;
}
public IQueryable<IPost> Popularity(IQueryable<IPost> source, bool useThenBy, bool desc)
{
var result = useThenBy ?
((IOrderedQueryable<IPost>)source).ThenBy(p => p.LikeCount) :
source.OrderBy(p => p.LikeCount)
.ThenBy(p => p.CommentCount)
.ThenBy(p => p.DateCreated);
return result;
}
public IQueryable<T> Oldest<T>(IQueryable<T> source, bool useThenBy, bool desc) where T : IBaseEntity
{
var result = useThenBy ?
((IOrderedQueryable<T>)source).ThenByDescending(p => p.DateCreated) :
source.OrderByDescending(p => p.DateCreated);
return result;
}
}
}