Preference.cs 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. using System;
  2. using System.ComponentModel.DataAnnotations;
  3. using System.ComponentModel.DataAnnotations.Schema;
  4. using Jellyfin.Data.Enums;
  5. using Jellyfin.Data.Interfaces;
  6. namespace Jellyfin.Data.Entities
  7. {
  8. /// <summary>
  9. /// An entity representing a preference attached to a user or group.
  10. /// </summary>
  11. public class Preference : IHasConcurrencyToken
  12. {
  13. /// <summary>
  14. /// Initializes a new instance of the <see cref="Preference"/> class.
  15. /// Public constructor with required data.
  16. /// </summary>
  17. /// <param name="kind">The preference kind.</param>
  18. /// <param name="value">The value.</param>
  19. public Preference(PreferenceKind kind, string value)
  20. {
  21. Kind = kind;
  22. Value = value ?? throw new ArgumentNullException(nameof(value));
  23. }
  24. /// <summary>
  25. /// Gets the id of this preference.
  26. /// </summary>
  27. /// <remarks>
  28. /// Identity, Indexed, Required.
  29. /// </remarks>
  30. [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
  31. public int Id { get; private set; }
  32. /// <summary>
  33. /// Gets or sets the id of the associated user.
  34. /// </summary>
  35. public Guid? UserId { get; set; }
  36. /// <summary>
  37. /// Gets the type of this preference.
  38. /// </summary>
  39. /// <remarks>
  40. /// Required.
  41. /// </remarks>
  42. public PreferenceKind Kind { get; private set; }
  43. /// <summary>
  44. /// Gets or sets the value of this preference.
  45. /// </summary>
  46. /// <remarks>
  47. /// Required, Max length = 65535.
  48. /// </remarks>
  49. [MaxLength(65535)]
  50. [StringLength(65535)]
  51. public string Value { get; set; }
  52. /// <inheritdoc/>
  53. [ConcurrencyCheck]
  54. public uint RowVersion { get; private set; }
  55. /// <inheritdoc/>
  56. public void OnSavingChanges()
  57. {
  58. RowVersion++;
  59. }
  60. }
  61. }