mirror of
https://github.com/anjoy8/Blog.Core.git
synced 2024-09-20 23:48:27 +08:00
47 lines
1.2 KiB
C#
47 lines
1.2 KiB
C#
using Blog.Core.Common;
|
|
using Blog.Core.IRepository.Base;
|
|
using Blog.Core.IServices;
|
|
using Blog.Core.Model.Models;
|
|
using Blog.Core.Services.BASE;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace Blog.Core.Services
|
|
{
|
|
/// <summary>
|
|
/// RoleServices
|
|
/// </summary>
|
|
public class RoleServices : BaseServices<Role>, IRoleServices
|
|
{
|
|
/// <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);
|
|
}
|
|
}
|
|
}
|