2018-01-27 07:37:38 +01:00
|
|
|
|
using Sieve.Services;
|
|
|
|
|
using SieveTests.Entities;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace SieveTests.Services
|
|
|
|
|
{
|
2018-02-07 05:43:09 +01:00
|
|
|
|
public class SieveCustomSortMethods : ISieveCustomSortMethods
|
2018-01-27 07:37:38 +01: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)
|
|
|
|
|
.ThenBy(p => p.CommentCount)
|
|
|
|
|
.ThenBy(p => p.DateCreated);
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|