jellyfin-server/Jellyfin.Data/Entities/Libraries/Rating.cs

79 lines
2.2 KiB
C#
Raw Normal View History

using System;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using Jellyfin.Data.Interfaces;
2020-08-29 17:30:09 +00:00
namespace Jellyfin.Data.Entities.Libraries
{
/// <summary>
/// An entity representing a rating for an entity.
/// </summary>
public class Rating : IHasConcurrencyToken
2020-05-02 21:56:05 +00:00
{
/// <summary>
/// Initializes a new instance of the <see cref="Rating"/> class.
2020-05-02 21:56:05 +00:00
/// </summary>
/// <param name="value">The value.</param>
2020-09-01 15:38:09 +00:00
/// <param name="itemMetadata">The metadata.</param>
public Rating(double value, ItemMetadata itemMetadata)
2020-05-02 21:56:05 +00:00
{
Value = value;
2020-05-02 21:56:05 +00:00
2020-09-01 15:38:09 +00:00
if (itemMetadata == null)
2020-06-20 08:35:29 +00:00
{
2020-09-01 15:38:09 +00:00
throw new ArgumentNullException(nameof(itemMetadata));
2020-06-20 08:35:29 +00:00
}
2020-05-02 21:56:05 +00:00
2020-09-01 15:38:09 +00:00
itemMetadata.Ratings.Add(this);
2020-05-02 21:56:05 +00:00
}
/// <summary>
/// Initializes a new instance of the <see cref="Rating"/> class.
2020-05-02 21:56:05 +00:00
/// </summary>
/// <remarks>
/// Default constructor. Protected due to required properties, but present because EF needs it.
/// </remarks>
protected Rating()
2020-05-02 21:56:05 +00:00
{
}
/// <summary>
/// Gets or sets the id.
2020-05-02 21:56:05 +00:00
/// </summary>
/// <remarks>
/// Identity, Indexed, Required.
/// </remarks>
2020-05-02 21:56:05 +00:00
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int Id { get; protected set; }
2020-05-02 21:56:05 +00:00
/// <summary>
/// Gets or sets the value.
2020-05-02 21:56:05 +00:00
/// </summary>
/// <remarks>
/// Required.
/// </remarks>
public double Value { get; set; }
2020-06-15 21:43:52 +00:00
2020-05-02 21:56:05 +00:00
/// <summary>
/// Gets or sets the number of votes.
2020-05-02 21:56:05 +00:00
/// </summary>
public int? Votes { get; set; }
2020-06-15 21:43:52 +00:00
/// <inheritdoc />
[ConcurrencyCheck]
public uint RowVersion { get; set; }
2020-05-02 21:56:05 +00:00
/// <summary>
/// Gets or sets the rating type.
/// If this is <c>null</c> it's the internal user rating.
2020-05-02 21:56:05 +00:00
/// </summary>
public virtual RatingSource RatingType { get; set; }
2020-05-02 21:56:05 +00:00
/// <inheritdoc />
2020-05-02 21:56:05 +00:00
public void OnSavingChanges()
{
RowVersion++;
}
}
}