UserItemData.cs 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. using System;
  2. using System.Runtime.Serialization;
  3. namespace MediaBrowser.Controller.Entities
  4. {
  5. public class UserItemData
  6. {
  7. private float? _rating;
  8. /// <summary>
  9. /// Gets or sets the users 0-10 rating
  10. /// </summary>
  11. public float? Rating
  12. {
  13. get
  14. {
  15. return _rating;
  16. }
  17. set
  18. {
  19. if (value.HasValue)
  20. {
  21. if (value.Value < 0 || value.Value > 10)
  22. {
  23. throw new InvalidOperationException("A 0-10 rating is required for UserItemData.");
  24. }
  25. }
  26. _rating = value;
  27. }
  28. }
  29. public long PlaybackPositionTicks { get; set; }
  30. public int PlayCount { get; set; }
  31. public bool IsFavorite { get; set; }
  32. /// <summary>
  33. /// This is an interpreted property to indicate likes or dislikes
  34. /// This should never be serialized.
  35. /// </summary>
  36. [IgnoreDataMember]
  37. public bool? Likes
  38. {
  39. get
  40. {
  41. if (Rating != null)
  42. {
  43. return Rating >= 6.5;
  44. }
  45. return null;
  46. }
  47. set
  48. {
  49. if (value.HasValue)
  50. {
  51. Rating = value.Value ? 10 : 1;
  52. }
  53. else
  54. {
  55. Rating = null;
  56. }
  57. }
  58. }
  59. }
  60. }