diff options
Diffstat (limited to 'Jellyfin.Data/Entities/Libraries/Rating.cs')
| -rw-r--r-- | Jellyfin.Data/Entities/Libraries/Rating.cs | 186 |
1 files changed, 35 insertions, 151 deletions
diff --git a/Jellyfin.Data/Entities/Libraries/Rating.cs b/Jellyfin.Data/Entities/Libraries/Rating.cs index 31bee165af..ba054a39e0 100644 --- a/Jellyfin.Data/Entities/Libraries/Rating.cs +++ b/Jellyfin.Data/Entities/Libraries/Rating.cs @@ -1,194 +1,78 @@ -#pragma warning disable CS1591 - using System; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; +using Jellyfin.Data.Interfaces; namespace Jellyfin.Data.Entities.Libraries { - public partial class Rating + /// <summary> + /// An entity representing a rating for an entity. + /// </summary> + public class Rating : IHasConcurrencyToken { - partial void Init(); - /// <summary> - /// Default constructor. Protected due to required properties, but present because EF needs it. + /// Initializes a new instance of the <see cref="Rating"/> class. /// </summary> - protected Rating() + /// <param name="value">The value.</param> + /// <param name="metadata">The metadata.</param> + public Rating(double value, Metadata metadata) { - Init(); - } + Value = value; - /// <summary> - /// Replaces default constructor, since it's protected. Caller assumes responsibility for setting all required values before saving. - /// </summary> - public static Rating CreateRatingUnsafe() - { - return new Rating(); - } - - /// <summary> - /// Public constructor with required data. - /// </summary> - /// <param name="value"></param> - /// <param name="_metadata0"></param> - public Rating(double value, Metadata _metadata0) - { - this.Value = value; - - if (_metadata0 == null) + if (metadata == null) { - throw new ArgumentNullException(nameof(_metadata0)); + throw new ArgumentNullException(nameof(metadata)); } - _metadata0.Ratings.Add(this); - - Init(); + metadata.Ratings.Add(this); } /// <summary> - /// Static create function (for use in LINQ queries, etc.) + /// Initializes a new instance of the <see cref="Rating"/> class. /// </summary> - /// <param name="value"></param> - /// <param name="_metadata0"></param> - public static Rating Create(double value, Metadata _metadata0) + /// <remarks> + /// Default constructor. Protected due to required properties, but present because EF needs it. + /// </remarks> + protected Rating() { - return new Rating(value, _metadata0); } - /************************************************************************* - * Properties - *************************************************************************/ - - /// <summary> - /// Backing field for Id. - /// </summary> - internal int _Id; - /// <summary> - /// When provided in a partial class, allows value of Id to be changed before setting. - /// </summary> - partial void SetId(int oldValue, ref int newValue); /// <summary> - /// When provided in a partial class, allows value of Id to be changed before returning. + /// Gets or sets the id. /// </summary> - partial void GetId(ref int result); - - /// <summary> + /// <remarks> /// Identity, Indexed, Required. - /// </summary> - [Key] - [Required] + /// </remarks> [DatabaseGenerated(DatabaseGeneratedOption.Identity)] - public int Id - { - get - { - int value = _Id; - GetId(ref value); - return _Id = value; - } - - protected set - { - int oldValue = _Id; - SetId(oldValue, ref value); - if (oldValue != value) - { - _Id = value; - } - } - } + public int Id { get; protected set; } /// <summary> - /// Backing field for Value. - /// </summary> - protected double _Value; - /// <summary> - /// When provided in a partial class, allows value of Value to be changed before setting. + /// Gets or sets the value. /// </summary> - partial void SetValue(double oldValue, ref double newValue); - /// <summary> - /// When provided in a partial class, allows value of Value to be changed before returning. - /// </summary> - partial void GetValue(ref double result); - - /// <summary> + /// <remarks> /// Required. - /// </summary> - [Required] - public double Value - { - get - { - double value = _Value; - GetValue(ref value); - return _Value = value; - } + /// </remarks> + public double Value { get; set; } - set - { - double oldValue = _Value; - SetValue(oldValue, ref value); - if (oldValue != value) - { - _Value = value; - } - } - } - - /// <summary> - /// Backing field for Votes. - /// </summary> - protected int? _Votes; - /// <summary> - /// When provided in a partial class, allows value of Votes to be changed before setting. - /// </summary> - partial void SetVotes(int? oldValue, ref int? newValue); /// <summary> - /// When provided in a partial class, allows value of Votes to be changed before returning. + /// Gets or sets the number of votes. /// </summary> - partial void GetVotes(ref int? result); - - public int? Votes - { - get - { - int? value = _Votes; - GetVotes(ref value); - return _Votes = value; - } + public int? Votes { get; set; } - set - { - int? oldValue = _Votes; - SetVotes(oldValue, ref value); - if (oldValue != value) - { - _Votes = value; - } - } - } + /// <inheritdoc /> + [ConcurrencyCheck] + public uint RowVersion { get; set; } /// <summary> - /// Required, ConcurrenyToken. + /// Gets or sets the rating type. + /// If this is <c>null</c> it's the internal user rating. /// </summary> - [ConcurrencyCheck] - [Required] - public uint RowVersion { get; set; } + public virtual RatingSource RatingType { get; set; } + /// <inheritdoc /> public void OnSavingChanges() { RowVersion++; } - - /************************************************************************* - * Navigation properties - *************************************************************************/ - - /// <summary> - /// If this is NULL it's the internal user rating. - /// </summary> - [ForeignKey("RatingSource_RatingType_Id")] - public virtual RatingSource RatingType { get; set; } } } - |
