Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

IQueryableExtensions.cs 1.1KB

123456789101112131415161718192021222324252627282930313233
  1. using System.Linq.Expressions;
  2. using BlackRock.Reporting.API.Mediator;
  3. using BlackRock.Reporting.API.Mediator.Model;
  4. namespace BlackRock.Reporting.API.Extensions
  5. {
  6. public static class IQueryableExtensions
  7. {
  8. public static IQueryable<T> ApplyOrdering<T>(this IQueryable<T> query,
  9. IPaggingAndFiltering queryObj, Dictionary<string, Expression<Func<T, object>>> columnsMap)
  10. {
  11. if (string.IsNullOrWhiteSpace(queryObj.SortBy) ||
  12. !columnsMap.ContainsKey(queryObj.SortBy))
  13. return query;
  14. if (queryObj.IsSortAscending)
  15. return query.OrderBy(columnsMap[queryObj.SortBy]);
  16. return query.OrderByDescending(columnsMap[queryObj.SortBy]);
  17. }
  18. public static IQueryable<T> ApplyPagging<T>(this IQueryable<T> query,
  19. IPaggingAndFiltering queryObj)
  20. {
  21. if (queryObj.Page <= 0)
  22. queryObj.Page = 1;
  23. if (queryObj.PageSize <= 0)
  24. queryObj.PageSize = 10;
  25. return query.Skip((queryObj.Page - 1) * queryObj.PageSize)
  26. .Take(queryObj.PageSize);
  27. }
  28. }
  29. }