mirror of
https://gitee.com/dotnetchina/OpenAuth.Net.git
synced 2025-09-20 10:37:55 +08:00
增加撤销与启动,详见:#I3ILBG
调整工程结构,采用模块化机制
This commit is contained in:
6
OpenAuth.App/RoleManager/Request/QueryRoleListReq.cs
Normal file
6
OpenAuth.App/RoleManager/Request/QueryRoleListReq.cs
Normal file
@@ -0,0 +1,6 @@
|
||||
namespace OpenAuth.App.Request
|
||||
{
|
||||
public class QueryRoleListReq : PageReq
|
||||
{
|
||||
}
|
||||
}
|
60
OpenAuth.App/RoleManager/Response/RoleView.cs
Normal file
60
OpenAuth.App/RoleManager/Response/RoleView.cs
Normal file
@@ -0,0 +1,60 @@
|
||||
// ***********************************************************************
|
||||
// Assembly : OpenAuth.App
|
||||
// Author : yubaolee
|
||||
// Created : 11-29-2015
|
||||
//
|
||||
// Last Modified By : yubaolee
|
||||
// Last Modified On : 11-29-2015
|
||||
// ***********************************************************************
|
||||
// <copyright file="RoleVM.cs" company="www.cnblogs.com/yubaolee">
|
||||
// Copyright (c) www.cnblogs.com/yubaolee. All rights reserved.
|
||||
// </copyright>
|
||||
// <summary>角色模型视图</summary>
|
||||
// ***********************************************************************
|
||||
|
||||
using Infrastructure;
|
||||
using OpenAuth.Repository.Domain;
|
||||
|
||||
namespace OpenAuth.App.Response
|
||||
{
|
||||
public partial class RoleView
|
||||
{
|
||||
/// <summary>
|
||||
/// 用户ID
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public string Id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 名称
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public string Name { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 当前状态
|
||||
/// </summary>
|
||||
public int Status { get; set; }
|
||||
/// <summary>
|
||||
/// 角色类型
|
||||
/// </summary>
|
||||
public int Type { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
///是否属于某用户
|
||||
/// </summary>
|
||||
public bool Checked { get; set; }
|
||||
|
||||
public static implicit operator RoleView(Role role)
|
||||
{
|
||||
return role.MapTo<RoleView>();
|
||||
}
|
||||
|
||||
public static implicit operator Role(RoleView rolevm)
|
||||
{
|
||||
return rolevm.MapTo<Role>();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
84
OpenAuth.App/RoleManager/RoleApp.cs
Normal file
84
OpenAuth.App/RoleManager/RoleApp.cs
Normal file
@@ -0,0 +1,84 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using OpenAuth.App.Interface;
|
||||
using OpenAuth.App.Response;
|
||||
using OpenAuth.Repository.Domain;
|
||||
using OpenAuth.Repository.Interface;
|
||||
using System.Linq;
|
||||
using Infrastructure;
|
||||
using OpenAuth.App.Request;
|
||||
using OpenAuth.Repository;
|
||||
|
||||
namespace OpenAuth.App
|
||||
{
|
||||
public class RoleApp : BaseStringApp<Role,OpenAuthDBContext>
|
||||
{
|
||||
private RevelanceManagerApp _revelanceApp;
|
||||
|
||||
/// <summary>
|
||||
/// 加载当前登录用户可访问的全部角色
|
||||
/// </summary>
|
||||
public List<Role> Load(QueryRoleListReq request)
|
||||
{
|
||||
var loginUser = _auth.GetCurrentUser();
|
||||
var roles = loginUser.Roles;
|
||||
if (!string.IsNullOrEmpty(request.key))
|
||||
{
|
||||
roles = roles.Where(u => u.Name.Contains(request.key)).ToList();
|
||||
}
|
||||
|
||||
return roles;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 添加角色,如果当前登录用户不是System,则直接把新角色分配给当前登录用户
|
||||
/// </summary>
|
||||
public void Add(RoleView obj)
|
||||
{
|
||||
UnitWork.ExecuteWithTransaction(() =>
|
||||
{
|
||||
Role role = obj;
|
||||
role.CreateTime = DateTime.Now;
|
||||
UnitWork.Add(role);
|
||||
UnitWork.Save();
|
||||
obj.Id = role.Id; //要把保存后的ID存入view
|
||||
|
||||
//如果当前账号不是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}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 更新角色属性
|
||||
/// </summary>
|
||||
/// <param name="obj"></param>
|
||||
public void Update(RoleView obj)
|
||||
{
|
||||
Role role = obj;
|
||||
|
||||
UnitWork.Update<Role>(u => u.Id == obj.Id, u => new Role
|
||||
{
|
||||
Name = role.Name,
|
||||
Status = role.Status
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
|
||||
public RoleApp(IUnitWork<OpenAuthDBContext> unitWork, IRepository<Role,OpenAuthDBContext> repository,
|
||||
RevelanceManagerApp app,IAuth auth) : base(unitWork, repository, auth)
|
||||
{
|
||||
_revelanceApp = app;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user