Artwork.cs 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. #pragma warning disable CA2227
  2. using System;
  3. using System.ComponentModel.DataAnnotations;
  4. using System.ComponentModel.DataAnnotations.Schema;
  5. using Jellyfin.Data.Enums;
  6. using Jellyfin.Data.Interfaces;
  7. namespace Jellyfin.Data.Entities.Libraries
  8. {
  9. /// <summary>
  10. /// An entity representing artwork.
  11. /// </summary>
  12. public class Artwork : IHasConcurrencyToken
  13. {
  14. /// <summary>
  15. /// Initializes a new instance of the <see cref="Artwork"/> class.
  16. /// </summary>
  17. /// <param name="path">The path.</param>
  18. /// <param name="kind">The kind of art.</param>
  19. /// <param name="owner">The owner.</param>
  20. public Artwork(string path, ArtKind kind, IHasArtwork owner)
  21. {
  22. if (string.IsNullOrEmpty(path))
  23. {
  24. throw new ArgumentNullException(nameof(path));
  25. }
  26. Path = path;
  27. Kind = kind;
  28. owner?.Artwork.Add(this);
  29. }
  30. /// <summary>
  31. /// Initializes a new instance of the <see cref="Artwork"/> class.
  32. /// </summary>
  33. /// <remarks>
  34. /// Default constructor. Protected due to required properties, but present because EF needs it.
  35. /// </remarks>
  36. protected Artwork()
  37. {
  38. }
  39. /// <summary>
  40. /// Gets or sets the id.
  41. /// </summary>
  42. /// <remarks>
  43. /// Identity, Indexed, Required.
  44. /// </remarks>
  45. [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
  46. public int Id { get; protected set; }
  47. /// <summary>
  48. /// Gets or sets the path.
  49. /// </summary>
  50. /// <remarks>
  51. /// Required, Max length = 65535.
  52. /// </remarks>
  53. [Required]
  54. [MaxLength(65535)]
  55. [StringLength(65535)]
  56. public string Path { get; set; }
  57. /// <summary>
  58. /// Gets or sets the kind of artwork.
  59. /// </summary>
  60. /// <remarks>
  61. /// Required.
  62. /// </remarks>
  63. public ArtKind Kind { get; set; }
  64. /// <inheritdoc />
  65. [ConcurrencyCheck]
  66. public uint RowVersion { get; set; }
  67. /// <inheritdoc />
  68. public void OnSavingChanges()
  69. {
  70. RowVersion++;
  71. }
  72. }
  73. }