Permission.cs 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. using System;
  2. using System.ComponentModel;
  3. using System.ComponentModel.DataAnnotations;
  4. using System.ComponentModel.DataAnnotations.Schema;
  5. using System.Runtime.CompilerServices;
  6. namespace Jellyfin.Data.Entities
  7. {
  8. public partial class Permission
  9. {
  10. partial void Init();
  11. /// <summary>
  12. /// Default constructor. Protected due to required properties, but present because EF needs it.
  13. /// </summary>
  14. protected Permission()
  15. {
  16. Init();
  17. }
  18. /// <summary>
  19. /// Replaces default constructor, since it's protected. Caller assumes responsibility for setting all required values before saving.
  20. /// </summary>
  21. public static Permission CreatePermissionUnsafe()
  22. {
  23. return new Permission();
  24. }
  25. /// <summary>
  26. /// Public constructor with required data
  27. /// </summary>
  28. /// <param name="kind"></param>
  29. /// <param name="value"></param>
  30. /// <param name="_user0"></param>
  31. /// <param name="_group1"></param>
  32. public Permission(Enums.PermissionKind kind, bool value, User _user0, Group _group1)
  33. {
  34. this.Kind = kind;
  35. this.Value = value;
  36. if (_user0 == null) throw new ArgumentNullException(nameof(_user0));
  37. _user0.Permissions.Add(this);
  38. if (_group1 == null) throw new ArgumentNullException(nameof(_group1));
  39. _group1.GroupPermissions.Add(this);
  40. Init();
  41. }
  42. /// <summary>
  43. /// Static create function (for use in LINQ queries, etc.)
  44. /// </summary>
  45. /// <param name="kind"></param>
  46. /// <param name="value"></param>
  47. /// <param name="_user0"></param>
  48. /// <param name="_group1"></param>
  49. public static Permission Create(Enums.PermissionKind kind, bool value, User _user0, Group _group1)
  50. {
  51. return new Permission(kind, value, _user0, _group1);
  52. }
  53. /*************************************************************************
  54. * Properties
  55. *************************************************************************/
  56. /// <summary>
  57. /// Identity, Indexed, Required
  58. /// </summary>
  59. [Key]
  60. [Required]
  61. [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
  62. public int Id { get; protected set; }
  63. /// <summary>
  64. /// Backing field for Kind
  65. /// </summary>
  66. protected Enums.PermissionKind _Kind;
  67. /// <summary>
  68. /// When provided in a partial class, allows value of Kind to be changed before setting.
  69. /// </summary>
  70. partial void SetKind(Enums.PermissionKind oldValue, ref Enums.PermissionKind newValue);
  71. /// <summary>
  72. /// When provided in a partial class, allows value of Kind to be changed before returning.
  73. /// </summary>
  74. partial void GetKind(ref Enums.PermissionKind result);
  75. /// <summary>
  76. /// Required
  77. /// </summary>
  78. [Required]
  79. public Enums.PermissionKind Kind
  80. {
  81. get
  82. {
  83. Enums.PermissionKind value = _Kind;
  84. GetKind(ref value);
  85. return (_Kind = value);
  86. }
  87. set
  88. {
  89. Enums.PermissionKind oldValue = _Kind;
  90. SetKind(oldValue, ref value);
  91. if (oldValue != value)
  92. {
  93. _Kind = value;
  94. OnPropertyChanged();
  95. }
  96. }
  97. }
  98. /// <summary>
  99. /// Required
  100. /// </summary>
  101. [Required]
  102. public bool Value { get; set; }
  103. /// <summary>
  104. /// Required, ConcurrenyToken
  105. /// </summary>
  106. [ConcurrencyCheck]
  107. [Required]
  108. public uint RowVersion { get; set; }
  109. public void OnSavingChanges()
  110. {
  111. RowVersion++;
  112. }
  113. /*************************************************************************
  114. * Navigation properties
  115. *************************************************************************/
  116. public virtual event PropertyChangedEventHandler PropertyChanged;
  117. protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
  118. {
  119. PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
  120. }
  121. }
  122. }