jellyfin-server/Jellyfin.Data/Entities/Preference.cs

96 lines
2.9 KiB
C#
Raw Normal View History

using System;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
2020-05-15 21:24:01 +00:00
using Jellyfin.Data.Enums;
namespace Jellyfin.Data.Entities
{
2020-05-15 21:24:01 +00:00
/// <summary>
/// An entity representing a preference attached to a user or group.
/// </summary>
public class Preference : ISavingChanges
2020-05-02 21:56:05 +00:00
{
/// <summary>
2020-05-15 21:24:01 +00:00
/// Initializes a new instance of the <see cref="Preference"/> class.
/// Public constructor with required data.
2020-05-02 21:56:05 +00:00
/// </summary>
2020-05-15 21:24:01 +00:00
/// <param name="kind">The preference kind.</param>
/// <param name="value">The value.</param>
public Preference(PreferenceKind kind, string value)
2020-05-02 21:56:05 +00:00
{
2020-05-15 21:24:01 +00:00
Kind = kind;
Value = value ?? throw new ArgumentNullException(nameof(value));
2020-05-02 21:56:05 +00:00
}
/// <summary>
2020-05-15 21:24:01 +00:00
/// Initializes a new instance of the <see cref="Preference"/> class.
/// Default constructor. Protected due to required properties, but present because EF needs it.
2020-05-02 21:56:05 +00:00
/// </summary>
2020-05-15 21:24:01 +00:00
protected Preference()
2020-05-02 21:56:05 +00:00
{
}
/*************************************************************************
* Properties
*************************************************************************/
/// <summary>
2020-05-19 23:44:55 +00:00
/// Gets or sets the id of this preference.
2020-05-02 21:56:05 +00:00
/// </summary>
2020-05-19 23:44:55 +00:00
/// <remarks>
/// Identity, Indexed, Required.
/// </remarks>
2020-05-02 21:56:05 +00:00
[Key]
[Required]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int Id { get; protected set; }
/// <summary>
2020-05-19 23:44:55 +00:00
/// Gets or sets the type of this preference.
2020-05-02 21:56:05 +00:00
/// </summary>
2020-05-19 23:44:55 +00:00
/// <remarks>
/// Required.
/// </remarks>
2020-05-02 21:56:05 +00:00
[Required]
2020-05-19 23:44:55 +00:00
public PreferenceKind Kind { get; protected set; }
2020-05-02 21:56:05 +00:00
/// <summary>
2020-05-19 23:44:55 +00:00
/// Gets or sets the value of this preference.
2020-05-02 21:56:05 +00:00
/// </summary>
2020-05-19 23:44:55 +00:00
/// <remarks>
/// Required, Max length = 65535.
/// </remarks>
2020-05-02 21:56:05 +00:00
[Required]
[MaxLength(65535)]
[StringLength(65535)]
public string Value { get; set; }
/// <summary>
2020-05-19 23:44:55 +00:00
/// Gets or sets the row version.
2020-05-02 21:56:05 +00:00
/// </summary>
2020-05-19 23:44:55 +00:00
/// <remarks>
/// Required, ConcurrencyToken.
/// </remarks>
2020-05-02 21:56:05 +00:00
[ConcurrencyCheck]
[Required]
public uint RowVersion { get; set; }
2020-05-15 21:24:01 +00:00
/// <summary>
/// Static create function (for use in LINQ queries, etc.)
/// </summary>
/// <param name="kind">The preference kind.</param>
/// <param name="value">The value.</param>
/// <returns>The new instance.</returns>
public static Preference Create(PreferenceKind kind, string value)
{
return new Preference(kind, value);
}
/// <inheritdoc/>
2020-05-02 21:56:05 +00:00
public void OnSavingChanges()
{
RowVersion++;
}
}
}