Rating.cs 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. using System;
  2. using System.ComponentModel.DataAnnotations;
  3. using System.ComponentModel.DataAnnotations.Schema;
  4. using Jellyfin.Data.Interfaces;
  5. namespace Jellyfin.Data.Entities.Libraries
  6. {
  7. /// <summary>
  8. /// An entity representing a rating for an entity.
  9. /// </summary>
  10. public class Rating : IHasConcurrencyToken
  11. {
  12. /// <summary>
  13. /// Initializes a new instance of the <see cref="Rating"/> class.
  14. /// </summary>
  15. /// <param name="value">The value.</param>
  16. /// <param name="itemMetadata">The metadata.</param>
  17. public Rating(double value, ItemMetadata itemMetadata)
  18. {
  19. Value = value;
  20. if (itemMetadata == null)
  21. {
  22. throw new ArgumentNullException(nameof(itemMetadata));
  23. }
  24. itemMetadata.Ratings.Add(this);
  25. }
  26. /// <summary>
  27. /// Initializes a new instance of the <see cref="Rating"/> class.
  28. /// </summary>
  29. /// <remarks>
  30. /// Default constructor. Protected due to required properties, but present because EF needs it.
  31. /// </remarks>
  32. protected Rating()
  33. {
  34. }
  35. /// <summary>
  36. /// Gets or sets the id.
  37. /// </summary>
  38. /// <remarks>
  39. /// Identity, Indexed, Required.
  40. /// </remarks>
  41. [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
  42. public int Id { get; protected set; }
  43. /// <summary>
  44. /// Gets or sets the value.
  45. /// </summary>
  46. /// <remarks>
  47. /// Required.
  48. /// </remarks>
  49. public double Value { get; set; }
  50. /// <summary>
  51. /// Gets or sets the number of votes.
  52. /// </summary>
  53. public int? Votes { get; set; }
  54. /// <inheritdoc />
  55. [ConcurrencyCheck]
  56. public uint RowVersion { get; set; }
  57. /// <summary>
  58. /// Gets or sets the rating type.
  59. /// If this is <c>null</c> it's the internal user rating.
  60. /// </summary>
  61. public virtual RatingSource RatingType { get; set; }
  62. /// <inheritdoc />
  63. public void OnSavingChanges()
  64. {
  65. RowVersion++;
  66. }
  67. }
  68. }