PersonRole.cs 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. using System;
  2. using System.Collections.Generic;
  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 a person's role in media.
  11. /// </summary>
  12. public class PersonRole : IHasArtwork, IHasConcurrencyToken
  13. {
  14. /// <summary>
  15. /// Initializes a new instance of the <see cref="PersonRole"/> class.
  16. /// </summary>
  17. /// <param name="type">The role type.</param>
  18. /// <param name="metadata">The metadata.</param>
  19. public PersonRole(PersonRoleType type, Metadata metadata)
  20. {
  21. Type = type;
  22. if (metadata == null)
  23. {
  24. throw new ArgumentNullException(nameof(metadata));
  25. }
  26. metadata.PersonRoles.Add(this);
  27. Sources = new HashSet<MetadataProviderId>();
  28. }
  29. /// <summary>
  30. /// Initializes a new instance of the <see cref="PersonRole"/> class.
  31. /// </summary>
  32. /// <remarks>
  33. /// Default constructor. Protected due to required properties, but present because EF needs it.
  34. /// </remarks>
  35. protected PersonRole()
  36. {
  37. }
  38. /// <summary>
  39. /// Gets or sets the id.
  40. /// </summary>
  41. /// <remarks>
  42. /// Identity, Indexed, Required.
  43. /// </remarks>
  44. [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
  45. public int Id { get; protected set; }
  46. /// <summary>
  47. /// Gets or sets the name of the person's role.
  48. /// </summary>
  49. /// <remarks>
  50. /// Max length = 1024.
  51. /// </remarks>
  52. [MaxLength(1024)]
  53. [StringLength(1024)]
  54. public string Role { get; set; }
  55. /// <summary>
  56. /// Gets or sets the person's role type.
  57. /// </summary>
  58. /// <remarks>
  59. /// Required.
  60. /// </remarks>
  61. public PersonRoleType Type { get; set; }
  62. /// <inheritdoc />
  63. [ConcurrencyCheck]
  64. public uint RowVersion { get; protected set; }
  65. /// <summary>
  66. /// Gets or sets the person.
  67. /// </summary>
  68. /// <remarks>
  69. /// Required.
  70. /// </remarks>
  71. [Required]
  72. public virtual Person Person { get; set; }
  73. /// <inheritdoc />
  74. public virtual ICollection<Artwork> Artwork { get; protected set; }
  75. /// <summary>
  76. /// Gets or sets a collection containing the metadata sources for this person role.
  77. /// </summary>
  78. public virtual ICollection<MetadataProviderId> Sources { get; protected set; }
  79. /// <inheritdoc />
  80. public void OnSavingChanges()
  81. {
  82. RowVersion++;
  83. }
  84. }
  85. }