Genre.cs 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. using System;
  2. using System.ComponentModel.DataAnnotations;
  3. using System.ComponentModel.DataAnnotations.Schema;
  4. using Jellyfin.Data.Interfaces;
  5. namespace Jellyfin.Data.Entities.Libraries
  6. {
  7. /// <summary>
  8. /// An entity representing a genre.
  9. /// </summary>
  10. public class Genre : IHasConcurrencyToken
  11. {
  12. /// <summary>
  13. /// Initializes a new instance of the <see cref="Genre"/> class.
  14. /// </summary>
  15. /// <param name="name">The name.</param>
  16. /// <param name="itemMetadata">The metadata.</param>
  17. public Genre(string name, ItemMetadata itemMetadata)
  18. {
  19. if (string.IsNullOrEmpty(name))
  20. {
  21. throw new ArgumentNullException(nameof(name));
  22. }
  23. Name = name;
  24. if (itemMetadata == null)
  25. {
  26. throw new ArgumentNullException(nameof(itemMetadata));
  27. }
  28. itemMetadata.Genres.Add(this);
  29. }
  30. /// <summary>
  31. /// Initializes a new instance of the <see cref="Genre"/> class.
  32. /// </summary>
  33. /// <remarks>
  34. /// Default constructor. Protected due to required properties, but present because EF needs it.
  35. /// </remarks>
  36. protected Genre()
  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.
  49. /// </summary>
  50. /// <remarks>
  51. /// Indexed, Required, Max length = 255.
  52. /// </remarks>
  53. [Required]
  54. [MaxLength(255)]
  55. [StringLength(255)]
  56. public string Name { get; set; }
  57. /// <inheritdoc />
  58. [ConcurrencyCheck]
  59. public uint RowVersion { get; protected set; }
  60. /// <inheritdoc />
  61. public void OnSavingChanges()
  62. {
  63. RowVersion++;
  64. }
  65. }
  66. }