jellyfin/Jellyfin.Data/Entities/Permission.cs

128 lines
3.7 KiB
C#
Raw Normal View History

using System;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Runtime.CompilerServices;
2020-05-15 23:24:01 +02:00
using Jellyfin.Data.Enums;
namespace Jellyfin.Data.Entities
{
2020-05-15 23:24:01 +02:00
public partial class Permission : ISavingChanges
2020-05-02 23:56:05 +02:00
{
partial void Init();
/// <summary>
/// Default constructor. Protected due to required properties, but present because EF needs it.
/// </summary>
protected Permission()
{
Init();
}
/// <summary>
/// Public constructor with required data
/// </summary>
/// <param name="kind"></param>
/// <param name="value"></param>
2020-05-15 23:24:01 +02:00
/// <param name="holderId"></param>
public Permission(PermissionKind kind, bool value)
2020-05-02 23:56:05 +02:00
{
2020-05-15 23:24:01 +02:00
Kind = kind;
Value = value;
2020-05-02 23:56:05 +02:00
Init();
}
/// <summary>
/// Static create function (for use in LINQ queries, etc.)
/// </summary>
/// <param name="kind"></param>
/// <param name="value"></param>
2020-05-15 23:24:01 +02:00
/// <param name="holderId"></param>
public static Permission Create(PermissionKind kind, bool value)
2020-05-02 23:56:05 +02:00
{
2020-05-15 23:24:01 +02:00
return new Permission(kind, value);
2020-05-02 23:56:05 +02:00
}
/*************************************************************************
* Properties
*************************************************************************/
/// <summary>
/// Identity, Indexed, Required
/// </summary>
[Key]
[Required]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int Id { get; protected set; }
/// <summary>
/// Backing field for Kind
/// </summary>
2020-05-15 23:24:01 +02:00
protected PermissionKind _Kind;
2020-05-02 23:56:05 +02:00
/// <summary>
/// When provided in a partial class, allows value of Kind to be changed before setting.
/// </summary>
2020-05-15 23:24:01 +02:00
partial void SetKind(PermissionKind oldValue, ref PermissionKind newValue);
2020-05-02 23:56:05 +02:00
/// <summary>
/// When provided in a partial class, allows value of Kind to be changed before returning.
/// </summary>
2020-05-15 23:24:01 +02:00
partial void GetKind(ref PermissionKind result);
2020-05-02 23:56:05 +02:00
/// <summary>
/// Required
/// </summary>
[Required]
2020-05-15 23:24:01 +02:00
public PermissionKind Kind
2020-05-02 23:56:05 +02:00
{
get
{
2020-05-15 23:24:01 +02:00
PermissionKind value = _Kind;
2020-05-02 23:56:05 +02:00
GetKind(ref value);
2020-05-15 23:24:01 +02:00
return _Kind = value;
}
2020-05-15 23:24:01 +02:00
2020-05-02 23:56:05 +02:00
set
{
2020-05-15 23:24:01 +02:00
PermissionKind oldValue = _Kind;
2020-05-02 23:56:05 +02:00
SetKind(oldValue, ref value);
if (oldValue != value)
{
_Kind = value;
OnPropertyChanged();
}
}
}
/// <summary>
/// Required
/// </summary>
[Required]
public bool Value { get; set; }
/// <summary>
2020-05-15 23:24:01 +02:00
/// Required, ConcurrencyToken.
2020-05-02 23:56:05 +02:00
/// </summary>
[ConcurrencyCheck]
[Required]
public uint RowVersion { get; set; }
public void OnSavingChanges()
{
RowVersion++;
}
/*************************************************************************
* Navigation properties
*************************************************************************/
public virtual event PropertyChangedEventHandler PropertyChanged;
protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}
}