Group.cs 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel.DataAnnotations;
  4. using System.ComponentModel.DataAnnotations.Schema;
  5. namespace Jellyfin.Data.Entities
  6. {
  7. public partial class Group
  8. {
  9. partial void Init();
  10. /// <summary>
  11. /// Default constructor. Protected due to required properties, but present because EF needs it.
  12. /// </summary>
  13. protected Group()
  14. {
  15. GroupPermissions = new HashSet<Permission>();
  16. ProviderMappings = new HashSet<ProviderMapping>();
  17. Preferences = new HashSet<Preference>();
  18. Init();
  19. }
  20. /// <summary>
  21. /// Replaces default constructor, since it's protected. Caller assumes responsibility for setting all required values before saving.
  22. /// </summary>
  23. public static Group CreateGroupUnsafe()
  24. {
  25. return new Group();
  26. }
  27. /// <summary>
  28. /// Public constructor with required data
  29. /// </summary>
  30. /// <param name="name"></param>
  31. /// <param name="_user0"></param>
  32. public Group(string name, User _user0)
  33. {
  34. if (string.IsNullOrEmpty(name)) throw new ArgumentNullException(nameof(name));
  35. this.Name = name;
  36. if (_user0 == null) throw new ArgumentNullException(nameof(_user0));
  37. _user0.Groups.Add(this);
  38. this.GroupPermissions = new HashSet<Permission>();
  39. this.ProviderMappings = new HashSet<ProviderMapping>();
  40. this.Preferences = new HashSet<Preference>();
  41. Init();
  42. }
  43. /// <summary>
  44. /// Static create function (for use in LINQ queries, etc.)
  45. /// </summary>
  46. /// <param name="name"></param>
  47. /// <param name="_user0"></param>
  48. public static Group Create(string name, User _user0)
  49. {
  50. return new Group(name, _user0);
  51. }
  52. /*************************************************************************
  53. * Properties
  54. *************************************************************************/
  55. /// <summary>
  56. /// Identity, Indexed, Required
  57. /// </summary>
  58. [Key]
  59. [Required]
  60. [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
  61. public int Id { get; protected set; }
  62. /// <summary>
  63. /// Required, Max length = 255
  64. /// </summary>
  65. [Required]
  66. [MaxLength(255)]
  67. [StringLength(255)]
  68. public string Name { get; set; }
  69. /// <summary>
  70. /// Required, ConcurrenyToken
  71. /// </summary>
  72. [ConcurrencyCheck]
  73. [Required]
  74. public uint RowVersion { get; set; }
  75. public void OnSavingChanges()
  76. {
  77. RowVersion++;
  78. }
  79. /*************************************************************************
  80. * Navigation properties
  81. *************************************************************************/
  82. [ForeignKey("Permission_GroupPermissions_Id")]
  83. public virtual ICollection<Permission> GroupPermissions { get; protected set; }
  84. [ForeignKey("ProviderMapping_ProviderMappings_Id")]
  85. public virtual ICollection<ProviderMapping> ProviderMappings { get; protected set; }
  86. [ForeignKey("Preference_Preferences_Id")]
  87. public virtual ICollection<Preference> Preferences { get; protected set; }
  88. }
  89. }