forked from raquelsa/AspNet.Identity.MySQL
-
Notifications
You must be signed in to change notification settings - Fork 0
/
RoleStore.cs
106 lines (87 loc) · 2.56 KB
/
RoleStore.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
using Microsoft.AspNet.Identity;
using System;
using System.Linq;
using System.Threading.Tasks;
namespace AspNet.Identity.MySQL
{
/// <summary>
/// Class that implements the key ASP.NET Identity role store iterfaces
/// </summary>
public class RoleStore<TRole> :
IRoleStore<TRole>,
IQueryableRoleStore<TRole>
where TRole : IdentityRole
{
private RoleTable<TRole> roleTable;
public MySQLDatabase Database { get; private set; }
public IQueryable<TRole> Roles
{
get
{
throw new NotImplementedException();
}
}
/// <summary>
/// Default constructor that initializes a new MySQLDatabase
/// instance using the Default Connection string
/// </summary>
public RoleStore()
: this(new MySQLDatabase())
{
}
/// <summary>
/// Constructor that takes a MySQLDatabase as argument
/// </summary>
/// <param name="database"></param>
public RoleStore(MySQLDatabase database)
{
Database = database;
roleTable = new RoleTable<TRole>(database);
}
public void Dispose()
{
if (Database != null)
{
Database.Dispose();
Database = null;
}
}
public Task CreateAsync(TRole role)
{
if (role == null)
{
throw new ArgumentNullException("role");
}
roleTable.Insert(role);
return Task.FromResult<object>(null);
}
public Task DeleteAsync(TRole role)
{
if (role == null)
{
throw new ArgumentNullException("user");
}
roleTable.Delete(role.Id);
return Task.FromResult<Object>(null);
}
public Task<TRole> FindByIdAsync(string roleId)
{
TRole result = roleTable.GetRoleById(roleId) as TRole;
return Task.FromResult<TRole>(result);
}
public Task<TRole> FindByNameAsync(string roleName)
{
TRole result = roleTable.GetRoleByName(roleName) as TRole;
return Task.FromResult<TRole>(result);
}
public Task UpdateAsync(TRole role)
{
if (role == null)
{
throw new ArgumentNullException("user");
}
roleTable.Update(role);
return Task.FromResult<Object>(null);
}
}
}