jellyfin/Jellyfin.Data/Entities/Permission.cs

130 lines
3.8 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 14:24:01 -07:00
using Jellyfin.Data.Enums;
namespace Jellyfin.Data.Entities
{
2020-05-15 14:24:01 -07:00
public partial class Permission : ISavingChanges
2020-05-02 14:56:05 -07:00
{
partial void Init();
/// <summary>
/// Initializes a new instance of the <see cref="Permission"/> class.
2020-05-02 14:56:05 -07:00
/// Public constructor with required data
/// </summary>
/// <param name="kind"></param>
/// <param name="value"></param>
2020-05-15 14:24:01 -07:00
/// <param name="holderId"></param>
public Permission(PermissionKind kind, bool value)
2020-05-02 14:56:05 -07:00
{
2020-05-15 14:24:01 -07:00
Kind = kind;
Value = value;
2020-05-02 14:56:05 -07:00
Init();
}
/// <summary>
/// Initializes a new instance of the <see cref="Permission"/> class.
/// Default constructor. Protected due to required properties, but present because EF needs it.
/// </summary>
protected Permission()
{
Init();
}
2020-05-02 14:56:05 -07:00
/// <summary>
/// Static create function (for use in LINQ queries, etc.)
/// </summary>
/// <param name="kind"></param>
/// <param name="value"></param>
2020-05-15 14:24:01 -07:00
/// <param name="holderId"></param>
public static Permission Create(PermissionKind kind, bool value)
2020-05-02 14:56:05 -07:00
{
2020-05-15 14:24:01 -07:00
return new Permission(kind, value);
2020-05-02 14:56:05 -07: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 14:24:01 -07:00
protected PermissionKind _Kind;
2020-05-02 14:56:05 -07:00
/// <summary>
/// When provided in a partial class, allows value of Kind to be changed before setting.
/// </summary>
2020-05-15 14:24:01 -07:00
partial void SetKind(PermissionKind oldValue, ref PermissionKind newValue);
2020-05-02 14:56:05 -07:00
/// <summary>
/// When provided in a partial class, allows value of Kind to be changed before returning.
/// </summary>
2020-05-15 14:24:01 -07:00
partial void GetKind(ref PermissionKind result);
2020-05-02 14:56:05 -07:00
/// <summary>
/// Required
/// </summary>
[Required]
2020-05-15 14:24:01 -07:00
public PermissionKind Kind
2020-05-02 14:56:05 -07:00
{
get
{
2020-05-15 14:24:01 -07:00
PermissionKind value = _Kind;
2020-05-02 14:56:05 -07:00
GetKind(ref value);
2020-05-15 14:24:01 -07:00
return _Kind = value;
}
2020-05-15 14:24:01 -07:00
2020-05-02 14:56:05 -07:00
set
{
2020-05-15 14:24:01 -07:00
PermissionKind oldValue = _Kind;
2020-05-02 14:56:05 -07:00
SetKind(oldValue, ref value);
if (oldValue != value)
{
_Kind = value;
OnPropertyChanged();
}
}
}
/// <summary>
/// Required
/// </summary>
[Required]
public bool Value { get; set; }
/// <summary>
2020-05-15 14:24:01 -07:00
/// Required, ConcurrencyToken.
2020-05-02 14:56:05 -07: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));
}
}
}