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