BudgetComparer.cs 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. using MediaBrowser.Controller.Entities;
  2. using MediaBrowser.Controller.Sorting;
  3. using MediaBrowser.Model.Querying;
  4. namespace MediaBrowser.Server.Implementations.Sorting
  5. {
  6. public class BudgetComparer : IBaseItemComparer
  7. {
  8. /// <summary>
  9. /// Compares the specified x.
  10. /// </summary>
  11. /// <param name="x">The x.</param>
  12. /// <param name="y">The y.</param>
  13. /// <returns>System.Int32.</returns>
  14. public int Compare(BaseItem x, BaseItem y)
  15. {
  16. return GetValue(x).CompareTo(GetValue(y));
  17. }
  18. private double GetValue(BaseItem x)
  19. {
  20. var hasBudget = x as IHasBudget;
  21. if (hasBudget != null)
  22. {
  23. return hasBudget.Budget ?? 0;
  24. }
  25. return 0;
  26. }
  27. /// <summary>
  28. /// Gets the name.
  29. /// </summary>
  30. /// <value>The name.</value>
  31. public string Name
  32. {
  33. get { return ItemSortBy.Budget; }
  34. }
  35. }
  36. }