2018-05-15 01:34:37 +02:00
|
|
|
|
using System.Linq;
|
|
|
|
|
using Sieve.Services;
|
2018-02-10 01:26:32 +01:00
|
|
|
|
using SieveUnitTests.Entities;
|
|
|
|
|
|
|
|
|
|
namespace SieveUnitTests.Services
|
|
|
|
|
{
|
|
|
|
|
public class SieveCustomSortMethods : ISieveCustomSortMethods
|
|
|
|
|
{
|
2018-05-25 10:30:44 +02:00
|
|
|
|
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)
|
2018-02-10 01:26:32 +01:00
|
|
|
|
.ThenBy(p => p.CommentCount)
|
|
|
|
|
.ThenBy(p => p.DateCreated);
|
2018-05-25 10:30:44 +02:00
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
2019-03-24 19:45:23 +01:00
|
|
|
|
|
|
|
|
|
public IQueryable<T> Oldest<T>(IQueryable<T> source, bool useThenBy, bool desc) where T : BaseEntity
|
|
|
|
|
{
|
|
|
|
|
var result = useThenBy ?
|
|
|
|
|
((IOrderedQueryable<T>)source).ThenByDescending(p => p.DateCreated) :
|
|
|
|
|
source.OrderByDescending(p => p.DateCreated);
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
2018-02-10 01:26:32 +01:00
|
|
|
|
}
|
|
|
|
|
}
|