OpenAuth.Net/OpenAuth.App/RoleApp.cs

82 lines
2.4 KiB
C#
Raw Normal View History

using System;
2017-12-14 20:36:56 +08:00
using System.Collections.Generic;
using OpenAuth.App.Interface;
2017-12-14 20:36:56 +08:00
using OpenAuth.App.Response;
using OpenAuth.Repository.Domain;
using OpenAuth.Repository.Interface;
using System.Linq;
using OpenAuth.App.Request;
2017-12-14 20:36:56 +08:00
namespace OpenAuth.App
{
public class RoleApp : BaseApp<Role>
{
private RevelanceManagerApp _revelanceApp;
2017-12-14 20:36:56 +08:00
/// <summary>
/// 加载当前登录用户可访问的全部角色
2017-12-14 20:36:56 +08:00
/// </summary>
public List<Role> Load(QueryRoleListReq request)
2017-12-14 20:36:56 +08:00
{
var loginUser = _auth.GetCurrentUser();
var roles = loginUser.Roles;
if (!string.IsNullOrEmpty(request.key))
2017-12-14 20:36:56 +08:00
{
roles = roles.Where(u => u.Name.Contains(request.key)).ToList();
2017-12-14 20:36:56 +08:00
}
return roles;
2017-12-14 20:36:56 +08:00
}
2020-12-27 00:00:28 +08:00
/// <summary>
/// 添加角色如果当前登录用户不是System则直接把新角色分配给当前登录用户
/// </summary>
2017-12-15 00:03:06 +08:00
public void Add(RoleView obj)
{
2020-12-27 00:00:28 +08:00
UnitWork.ExecuteWithTransaction(() =>
{
Role role = obj;
role.CreateTime = DateTime.Now;
UnitWork.Add(role);
UnitWork.Save();
obj.Id = role.Id; //要把保存后的ID存入view
2020-12-27 00:00:28 +08:00
//如果当前账号不是SYSTEM则直接分配
var loginUser = _auth.GetCurrentUser();
if (loginUser.User.Account != Define.SYSTEM_USERNAME)
{
_revelanceApp.Assign(new AssignReq
{
type = Define.USERROLE,
firstId = loginUser.User.Id,
secIds = new[] {role.Id}
});
}
});
2017-12-15 00:03:06 +08:00
}
2020-12-27 00:00:28 +08:00
/// <summary>
/// 更新角色属性
/// </summary>
/// <param name="obj"></param>
2017-12-15 00:03:06 +08:00
public void Update(RoleView obj)
{
Role role = obj;
2018-06-25 21:37:33 +08:00
UnitWork.Update<Role>(u => u.Id == obj.Id, u => new Role
2017-12-15 00:03:06 +08:00
{
Name = role.Name,
Status = role.Status
});
}
public RoleApp(IUnitWork unitWork, IRepository<Role> repository,
RevelanceManagerApp app,IAuth auth) : base(unitWork, repository, auth)
2017-12-15 00:03:06 +08:00
{
_revelanceApp = app;
2017-12-15 00:03:06 +08:00
}
2017-12-14 20:36:56 +08:00
}
}