mirror of
https://gitee.com/dotnetchina/OpenAuth.Net.git
synced 2025-12-26 22:25:39 +08:00
添加角色处理
This commit is contained in:
@@ -44,6 +44,7 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="LoginApp.cs" />
|
||||
<Compile Include="RoleManagerApp.cs" />
|
||||
<Compile Include="UserManagerApp.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="OrgManagerApp.cs" />
|
||||
|
||||
99
OpenAuth.App/RoleManagerApp.cs
Normal file
99
OpenAuth.App/RoleManagerApp.cs
Normal file
@@ -0,0 +1,99 @@
|
||||
using OpenAuth.App.ViewModel;
|
||||
using OpenAuth.Domain;
|
||||
using OpenAuth.Domain.Interface;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace OpenAuth.App
|
||||
{
|
||||
public class RoleManagerApp
|
||||
{
|
||||
private IRoleRepository _repository;
|
||||
private IOrgRepository _orgRepository;
|
||||
|
||||
public RoleManagerApp(IRoleRepository repository,
|
||||
IOrgRepository orgRepository)
|
||||
{
|
||||
_repository = repository;
|
||||
_orgRepository = orgRepository;
|
||||
}
|
||||
|
||||
public int GetRoleCntInOrg(int orgId)
|
||||
{
|
||||
if (orgId == 0)
|
||||
{
|
||||
return _repository.Find(null).Count();
|
||||
}
|
||||
else
|
||||
{
|
||||
return _repository.GetRoleCntInOrgs(GetSubOrgIds(orgId));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 加载一个部门及子部门全部Roles
|
||||
/// </summary>
|
||||
public dynamic Load(int orgId, int pageindex, int pagesize)
|
||||
{
|
||||
IEnumerable<Role> roles;
|
||||
int total = 0;
|
||||
if (orgId == 0)
|
||||
{
|
||||
roles = _repository.LoadRoles(pageindex, pagesize);
|
||||
total = _repository.GetCount();
|
||||
}
|
||||
else
|
||||
{
|
||||
roles = _repository.LoadInOrgs(pageindex, pagesize,GetSubOrgIds(orgId));
|
||||
total = _repository.GetRoleCntInOrgs(orgId);
|
||||
}
|
||||
|
||||
|
||||
return new
|
||||
{
|
||||
total = total,
|
||||
list = roles,
|
||||
pageCurrent = pageindex
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取当前组织的所有下级组织
|
||||
/// </summary>
|
||||
private int[] GetSubOrgIds(int orgId)
|
||||
{
|
||||
var org = _orgRepository.FindSingle(u => u.Id == orgId);
|
||||
var orgs = _orgRepository.Find(u => u.CascadeId.Contains(org.CascadeId)).Select(u => u.Id).ToArray();
|
||||
return orgs;
|
||||
}
|
||||
|
||||
public Role Find(int id)
|
||||
{
|
||||
return _repository.FindSingle(u => u.Id == id);
|
||||
|
||||
}
|
||||
|
||||
public void Delete(int id)
|
||||
{
|
||||
_repository.Delete(id);
|
||||
}
|
||||
|
||||
public void AddOrUpdate(Role view)
|
||||
{
|
||||
Role Role = view;
|
||||
if (Role.Id == 0)
|
||||
{
|
||||
Role.CreateTime = DateTime.Now;
|
||||
_repository.Add(Role);
|
||||
}
|
||||
else
|
||||
{
|
||||
_repository.Update(Role);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,82 +1,82 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Infrastructure;
|
||||
using OpenAuth.Domain;
|
||||
|
||||
namespace OpenAuth.App.ViewModel
|
||||
{
|
||||
public class UserView
|
||||
{
|
||||
/// <summary>
|
||||
/// 用户ID
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public int Id { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public string Account { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 组织名称
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public string Name { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public int Sex { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 当前状态
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public int Status { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 组织类型
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public int Type { get; set; }
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 创建时间
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public DateTime CreateTime { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 创建人名字
|
||||
/// </summary>
|
||||
/// <value>The create user.</value>
|
||||
public string CreateUser { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 所属组织名称,多个可用,分隔
|
||||
/// </summary>
|
||||
/// <value>The organizations.</value>
|
||||
public string Organizations { get; set; }
|
||||
|
||||
public string OrganizationIds { get; set; }
|
||||
|
||||
public static implicit operator UserView(User user)
|
||||
{
|
||||
return AutoMapperExt.ConvertTo<User, UserView>(user);
|
||||
}
|
||||
|
||||
public static implicit operator User(UserView view)
|
||||
{
|
||||
return AutoMapperExt.ConvertTo<UserView, User>(view);
|
||||
}
|
||||
}
|
||||
}
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Infrastructure;
|
||||
using OpenAuth.Domain;
|
||||
|
||||
namespace OpenAuth.App.ViewModel
|
||||
{
|
||||
public class UserView
|
||||
{
|
||||
/// <summary>
|
||||
/// 用户ID
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public int Id { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public string Account { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 组织名称
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public string Name { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public int Sex { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 当前状态
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public int Status { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 组织类型
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public int Type { get; set; }
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 创建时间
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public DateTime CreateTime { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 创建人名字
|
||||
/// </summary>
|
||||
/// <value>The create user.</value>
|
||||
public string CreateUser { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 所属组织名称,多个可用,分隔
|
||||
/// </summary>
|
||||
/// <value>The organizations.</value>
|
||||
public string Organizations { get; set; }
|
||||
|
||||
public string OrganizationIds { get; set; }
|
||||
|
||||
public static implicit operator UserView(User user)
|
||||
{
|
||||
return AutoMapperExt.ConvertTo<User, UserView>(user);
|
||||
}
|
||||
|
||||
public static implicit operator User(UserView view)
|
||||
{
|
||||
return AutoMapperExt.ConvertTo<UserView, User>(view);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user