PersonRole.cs 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. #pragma warning disable CA2227
  2. using System;
  3. using System.Collections.Generic;
  4. using System.ComponentModel.DataAnnotations;
  5. using System.ComponentModel.DataAnnotations.Schema;
  6. using Jellyfin.Data.Enums;
  7. using Jellyfin.Data.Interfaces;
  8. namespace Jellyfin.Data.Entities.Libraries
  9. {
  10. /// <summary>
  11. /// An entity representing a person's role in media.
  12. /// </summary>
  13. public class PersonRole : IHasArtwork, IHasConcurrencyToken
  14. {
  15. /// <summary>
  16. /// Initializes a new instance of the <see cref="PersonRole"/> class.
  17. /// </summary>
  18. /// <param name="type">The role type.</param>
  19. /// <param name="itemMetadata">The metadata.</param>
  20. public PersonRole(PersonRoleType type, ItemMetadata itemMetadata)
  21. {
  22. Type = type;
  23. if (itemMetadata == null)
  24. {
  25. throw new ArgumentNullException(nameof(itemMetadata));
  26. }
  27. itemMetadata.PersonRoles.Add(this);
  28. Sources = new HashSet<MetadataProviderId>();
  29. }
  30. /// <summary>
  31. /// Initializes a new instance of the <see cref="PersonRole"/> class.
  32. /// </summary>
  33. /// <remarks>
  34. /// Default constructor. Protected due to required properties, but present because EF needs it.
  35. /// </remarks>
  36. protected PersonRole()
  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 name of the person's role.
  49. /// </summary>
  50. /// <remarks>
  51. /// Max length = 1024.
  52. /// </remarks>
  53. [MaxLength(1024)]
  54. [StringLength(1024)]
  55. public string Role { get; set; }
  56. /// <summary>
  57. /// Gets or sets the person's role type.
  58. /// </summary>
  59. /// <remarks>
  60. /// Required.
  61. /// </remarks>
  62. public PersonRoleType Type { get; set; }
  63. /// <inheritdoc />
  64. [ConcurrencyCheck]
  65. public uint RowVersion { get; protected set; }
  66. /// <summary>
  67. /// Gets or sets the person.
  68. /// </summary>
  69. /// <remarks>
  70. /// Required.
  71. /// </remarks>
  72. [Required]
  73. public virtual Person Person { get; set; }
  74. /// <inheritdoc />
  75. public virtual ICollection<Artwork> Artwork { get; protected set; }
  76. /// <summary>
  77. /// Gets or sets a collection containing the metadata sources for this person role.
  78. /// </summary>
  79. public virtual ICollection<MetadataProviderId> Sources { get; protected set; }
  80. /// <inheritdoc />
  81. public void OnSavingChanges()
  82. {
  83. RowVersion++;
  84. }
  85. }
  86. }