forked from anjoy8/Blog.Core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRoleServices.cs
53 lines (48 loc) · 1.32 KB
/
RoleServices.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
using Blog.Core.IServices;
using Blog.Core.IRepository;
using Blog.Core.Services.BASE;
using Blog.Core.Model.Models;
using System.Threading.Tasks;
using System.Linq;
using Blog.Core.Common;
namespace Blog.Core.Services
{
/// <summary>
/// RoleServices
/// </summary>
public class RoleServices : BaseServices<Role>, IRoleServices
{
IRoleRepository _dal;
public RoleServices(IRoleRepository dal)
{
this._dal = dal;
base.BaseDal = dal;
}
/// <summary>
///
/// </summary>
/// <param name="roleName"></param>
/// <returns></returns>
public async Task<Role> SaveRole(string roleName)
{
Role role = new Role(roleName);
Role model = new Role();
var userList = await base.Query(a => a.Name == role.Name && a.Enabled);
if (userList.Count > 0)
{
model = userList.FirstOrDefault();
}
else
{
var id = await base.Add(role);
model = await base.QueryById(id);
}
return model;
}
[Caching(AbsoluteExpiration = 30)]
public async Task<string> GetRoleNameByRid(int rid)
{
return ((await base.QueryById(rid))?.Name);
}
}
}