You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
46 lines
1.2 KiB
46 lines
1.2 KiB
using Tiobon.Core.Common;
|
|
using Tiobon.Core.IRepository.Base;
|
|
using Tiobon.Core.IServices;
|
|
using Tiobon.Core.Model.Models;
|
|
using Tiobon.Core.Services.BASE;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace Tiobon.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);
|
|
}
|
|
}
|
|
}
|
|
|