public static IQueryable <ReleaseGrid> Sort(this IQueryable <ReleaseGrid> grids, BaseCriteria criteria) { criteria.Sorted = criteria.Sorted ?? "new"; switch (criteria.Sorted) { case "best": grids = grids.OrderByDescending(o => o.VoteUp + o.VoteDown + o.ViewCount); break; case "new": grids = grids.OrderByDescending(o => o.Date); break; case "old": grids = grids.OrderBy(o => o.Date); break; case "rating": grids = grids.OrderByDescending(o => o.QualityCount == 0 ? 0 : o.QualityScore / o.QualityCount); break; case "read": grids = grids.OrderByDescending(o => o.ViewCount); break; case "score": grids = grids.OrderByDescending(o => o.VoteUp - o.VoteDown); break; case "title": grids = grids.OrderBy(o => o.Title); break; case "vote": grids = grids.OrderByDescending(o => o.VoteUp + o.VoteDown); break; case "view": grids = grids.OrderByDescending(o => o.ViewCount); break; default: grids = grids.OrderByDescending(o => o.Date); break; } return(grids); }
public static IQueryable <CommentGrid> Sort(this IQueryable <CommentGrid> grids, BaseCriteria criteria) { criteria.Sorted = criteria.Sorted ?? "new"; switch (criteria.Sorted) { case "best": grids = grids.OrderByDescending(o => o.VoteUp + o.VoteDown + o.CommentCount); break; case "controversial": grids = grids.OrderByDescending(o => (o.VoteUp + o.VoteDown) + (Math.Abs(o.VoteUp.Value + o.VoteDown.Value) * -1)); break; case "new": grids = grids.OrderByDescending(o => o.InsertedDate); break; case "old": grids = grids.OrderBy(o => o.InsertedDate); break; case "reply": grids = grids.OrderByDescending(o => o.CommentCount); break; case "score": grids = grids.OrderByDescending(o => o.VoteUp - o.VoteDown); break; case "vote": grids = grids.OrderByDescending(o => o.VoteUp + o.VoteDown); break; default: grids = grids.OrderByDescending(o => o.InsertedDate); break; } return(grids); }