CollectionItem.cs 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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 collection item.
  9. /// </summary>
  10. public class CollectionItem : IHasConcurrencyToken
  11. {
  12. /// <summary>
  13. /// Initializes a new instance of the <see cref="CollectionItem"/> class.
  14. /// </summary>
  15. /// <param name="collection">The collection.</param>
  16. /// <param name="previous">The previous item.</param>
  17. /// <param name="next">The next item.</param>
  18. public CollectionItem(Collection collection, CollectionItem previous, CollectionItem next)
  19. {
  20. if (collection == null)
  21. {
  22. throw new ArgumentNullException(nameof(collection));
  23. }
  24. collection.Items.Add(this);
  25. if (next != null)
  26. {
  27. Next = next;
  28. next.Previous = this;
  29. }
  30. if (previous != null)
  31. {
  32. Previous = previous;
  33. previous.Next = this;
  34. }
  35. }
  36. /// <summary>
  37. /// Initializes a new instance of the <see cref="CollectionItem"/> class.
  38. /// </summary>
  39. /// <remarks>
  40. /// Default constructor. Protected due to required properties, but present because EF needs it.
  41. /// </remarks>
  42. protected CollectionItem()
  43. {
  44. }
  45. /// <summary>
  46. /// Gets or sets the id.
  47. /// </summary>
  48. /// <remarks>
  49. /// Identity, Indexed, Required.
  50. /// </remarks>
  51. [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
  52. public int Id { get; set; }
  53. /// <inheritdoc />
  54. [ConcurrencyCheck]
  55. public uint RowVersion { get; set; }
  56. /// <summary>
  57. /// Gets or sets the library item.
  58. /// </summary>
  59. /// <remarks>
  60. /// Required.
  61. /// </remarks>
  62. public virtual LibraryItem LibraryItem { get; set; }
  63. /// <summary>
  64. /// Gets or sets the next item in the collection.
  65. /// </summary>
  66. /// <remarks>
  67. /// TODO check if this properly updated dependant and has the proper principal relationship.
  68. /// </remarks>
  69. public virtual CollectionItem Next { get; set; }
  70. /// <summary>
  71. /// Gets or sets the previous item in the collection.
  72. /// </summary>
  73. /// <remarks>
  74. /// TODO check if this properly updated dependant and has the proper principal relationship.
  75. /// </remarks>
  76. public virtual CollectionItem Previous { get; set; }
  77. /// <inheritdoc />
  78. public void OnSavingChanges()
  79. {
  80. RowVersion++;
  81. }
  82. }
  83. }