2020-07-30 18:33:09 +08:00
|
|
|
using Blog.Core.Common;
|
|
|
|
using Blog.Core.IRepository.Base;
|
2018-11-07 12:54:10 +08:00
|
|
|
using Blog.Core.IServices;
|
|
|
|
using Blog.Core.Model.Models;
|
2020-07-30 18:33:09 +08:00
|
|
|
using Blog.Core.Services.BASE;
|
2018-11-07 12:54:10 +08:00
|
|
|
using System.Linq;
|
2020-07-30 18:33:09 +08:00
|
|
|
using System.Threading.Tasks;
|
2018-11-07 12:54:10 +08:00
|
|
|
|
|
|
|
namespace Blog.Core.Services
|
2020-07-30 18:33:09 +08:00
|
|
|
{
|
|
|
|
/// <summary>
|
|
|
|
/// RoleServices
|
|
|
|
/// </summary>
|
|
|
|
public class RoleServices : BaseServices<Role>, IRoleServices
|
2018-11-07 12:54:10 +08:00
|
|
|
{
|
|
|
|
/// <summary>
|
|
|
|
///
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="roleName"></param>
|
|
|
|
/// <returns></returns>
|
|
|
|
public async Task<Role> SaveRole(string roleName)
|
|
|
|
{
|
|
|
|
Role role = new Role(roleName);
|
|
|
|
Role model = new Role();
|
2019-03-25 11:11:17 +08:00
|
|
|
var userList = await base.Query(a => a.Name == role.Name && a.Enabled);
|
2018-11-07 12:54:10 +08:00
|
|
|
if (userList.Count > 0)
|
|
|
|
{
|
|
|
|
model = userList.FirstOrDefault();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-03-25 11:11:17 +08:00
|
|
|
var id = await base.Add(role);
|
2019-03-25 13:32:52 +08:00
|
|
|
model = await base.QueryById(id);
|
2018-11-07 12:54:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return model;
|
|
|
|
|
|
|
|
}
|
2019-02-20 19:21:15 +08:00
|
|
|
|
2019-02-25 17:05:10 +08:00
|
|
|
[Caching(AbsoluteExpiration = 30)]
|
2019-02-20 19:21:15 +08:00
|
|
|
public async Task<string> GetRoleNameByRid(int rid)
|
|
|
|
{
|
2019-03-25 13:32:52 +08:00
|
|
|
return ((await base.QueryById(rid))?.Name);
|
2019-02-20 19:21:15 +08:00
|
|
|
}
|
2018-11-07 12:54:10 +08:00
|
|
|
}
|
|
|
|
}
|