-
Notifications
You must be signed in to change notification settings - Fork 70
/
MongoIdentityRole.cs
110 lines (100 loc) · 3.44 KB
/
MongoIdentityRole.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
using AspNetCore.Identity.MongoDbCore.Extensions;
using AspNetCore.Identity.MongoDbCore.Interfaces;
using Microsoft.AspNetCore.Identity;
using MongoDbGenericRepository.Models;
using MongoDbGenericRepository.Utils;
using System;
using System.Collections.Generic;
namespace AspNetCore.Identity.MongoDbCore.Models
{
/// <summary>
/// A <see cref="MongoIdentityRole{TKey}"/> where TKey is a <see cref="string"/>
/// </summary>
public class MongoDbIdentityRole : MongoIdentityRole<string>
{
/// <summary>
/// The constructor for a <see cref="MongoDbIdentityRole"/>
/// </summary>
public MongoDbIdentityRole() : base()
{
}
/// <summary>
/// The constructor for a <see cref="MongoDbIdentityRole"/>, taking a role name.
/// </summary>
/// <param name="roleName">The name of the role.</param>
public MongoDbIdentityRole(string roleName) : base(roleName)
{
}
}
/// <summary>
/// A <see cref="MongoIdentityRole{TKey}"/> where TKey is a <see cref="Guid"/>
/// </summary>
public class MongoIdentityRole : MongoIdentityRole<Guid>
{
/// <summary>
/// The constructor for a <see cref="MongoIdentityRole"/>
/// </summary>
public MongoIdentityRole() : base()
{
}
/// <summary>
/// The constructor for a <see cref="MongoIdentityRole"/>, taking a role name.
/// </summary>
/// <param name="roleName">The name of the role.</param>
public MongoIdentityRole(string roleName) : base(roleName)
{
}
}
/// <summary>
/// A document representing an <see cref="IdentityRole{TKey}"/> document.
/// </summary>
/// <typeparam name="TKey">The type of the primary key.</typeparam>
public class MongoIdentityRole<TKey> : IdentityRole<TKey>, IDocument<TKey>, IClaimHolder
where TKey : IEquatable<TKey>
{
/// <summary>
/// The constructor for a <see cref="MongoIdentityRole{TKey}"/>
/// </summary>
public MongoIdentityRole()
{
InitializeFields();
}
/// <summary>
/// The constructor for a <see cref="MongoIdentityRole{TKey}"/>, taking a role name.
/// </summary>
/// <param name="roleName">The name of the role.</param>
public MongoIdentityRole(string roleName)
{
Name = roleName;
InitializeFields();
}
/// <summary>
/// Initialize the field of the MongoIdentityRole
/// </summary>
protected virtual void InitializeFields()
{
Version = 1;
Claims = new List<MongoClaim>();
Id = IdGenerator.GetId<TKey>();
}
/// <summary>
/// The constructor for a <see cref="MongoIdentityRole{TKey}"/>, taking a role name and a primary key value.
/// </summary>
/// <param name="name">The name of the role.</param>
/// <param name="key">The value of the primary key</param>
public MongoIdentityRole(string name, TKey key)
{
InitializeFields();
Id = key;
Name = Name;
}
/// <summary>
/// The version of the role schema
/// </summary>
public int Version { get; set; }
/// <summary>
/// The claims associated to the role
/// </summary>
public List<MongoClaim> Claims { get; set; }
}
}