mirror of
https://gitee.com/dotnetchina/OpenAuth.Net.git
synced 2025-04-05 17:38:01 +08:00
添加角色处理
This commit is contained in:
parent
6906e969ac
commit
119948ccb7
108
DB.sql
108
DB.sql
@ -1,6 +1,6 @@
|
||||
/*==============================================================*/
|
||||
/* DBMS name: Microsoft SQL Server 2008 */
|
||||
/* Created on: 2015/11/15 23:04:57 */
|
||||
/* Created on: 2015/11/19 21:22:16 */
|
||||
/*==============================================================*/
|
||||
|
||||
|
||||
@ -402,7 +402,7 @@ end
|
||||
|
||||
select @CurrentUser = user_name()
|
||||
execute sp_addextendedproperty 'MS_Description',
|
||||
'模块元素表',
|
||||
'模块元素表(需要权限控制的按钮)',
|
||||
'user', @CurrentUser, 'table', 'ModuleElement'
|
||||
go
|
||||
|
||||
@ -497,7 +497,7 @@ end
|
||||
|
||||
select @CurrentUser = user_name()
|
||||
execute sp_addextendedproperty 'MS_Description',
|
||||
'所属功能模块流水号',
|
||||
'功能模块Id',
|
||||
'user', @CurrentUser, 'table', 'ModuleElement', 'column', 'ModuleId'
|
||||
go
|
||||
|
||||
@ -587,7 +587,7 @@ end
|
||||
|
||||
select @CurrentUser = user_name()
|
||||
execute sp_addextendedproperty 'MS_Description',
|
||||
'页面元素流水号',
|
||||
'元素流水号',
|
||||
'user', @CurrentUser, 'table', 'ModuleElementGrant', 'column', 'ElementId'
|
||||
go
|
||||
|
||||
@ -777,6 +777,25 @@ execute sp_addextendedproperty 'MS_Description',
|
||||
'user', @CurrentUser, 'table', 'ModuleRole', 'column', 'OperateTime'
|
||||
go
|
||||
|
||||
if exists(select 1 from sys.extended_properties p where
|
||||
p.major_id = object_id('ModuleRole')
|
||||
and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'OperatorId')
|
||||
)
|
||||
begin
|
||||
declare @CurrentUser sysname
|
||||
select @CurrentUser = user_name()
|
||||
execute sp_dropextendedproperty 'MS_Description',
|
||||
'user', @CurrentUser, 'table', 'ModuleRole', 'column', 'OperatorId'
|
||||
|
||||
end
|
||||
|
||||
|
||||
select @CurrentUser = user_name()
|
||||
execute sp_addextendedproperty 'MS_Description',
|
||||
'授权人流水号',
|
||||
'user', @CurrentUser, 'table', 'ModuleRole', 'column', 'OperatorId'
|
||||
go
|
||||
|
||||
alter table ModuleRole
|
||||
add constraint PK_MODULEROLE primary key (Id)
|
||||
go
|
||||
@ -1133,14 +1152,15 @@ go
|
||||
/* Table: Role */
|
||||
/*==============================================================*/
|
||||
create table Role (
|
||||
Id int identity,
|
||||
Id int not null,
|
||||
Name varchar(255) not null default ' ',
|
||||
Status int not null default 1,
|
||||
Type int not null default 0,
|
||||
CreateTime datetime not null default getdate(),
|
||||
CreateId varchar(64) not null default ' ',
|
||||
CreateOrgId int not null default 0,
|
||||
CreateOrgCascadeId varchar(255) not null default ' '
|
||||
OrgId int not null default 0,
|
||||
OrgCascadeId varchar(255) not null default ' ',
|
||||
OrgName varchar(255) not null default ' '
|
||||
)
|
||||
go
|
||||
|
||||
@ -1277,40 +1297,59 @@ go
|
||||
|
||||
if exists(select 1 from sys.extended_properties p where
|
||||
p.major_id = object_id('Role')
|
||||
and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'CreateOrgId')
|
||||
and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'OrgId')
|
||||
)
|
||||
begin
|
||||
declare @CurrentUser sysname
|
||||
select @CurrentUser = user_name()
|
||||
execute sp_dropextendedproperty 'MS_Description',
|
||||
'user', @CurrentUser, 'table', 'Role', 'column', 'CreateOrgId'
|
||||
'user', @CurrentUser, 'table', 'Role', 'column', 'OrgId'
|
||||
|
||||
end
|
||||
|
||||
|
||||
select @CurrentUser = user_name()
|
||||
execute sp_addextendedproperty 'MS_Description',
|
||||
'创建人所属部门流水号',
|
||||
'user', @CurrentUser, 'table', 'Role', 'column', 'CreateOrgId'
|
||||
'所属部门流水号',
|
||||
'user', @CurrentUser, 'table', 'Role', 'column', 'OrgId'
|
||||
go
|
||||
|
||||
if exists(select 1 from sys.extended_properties p where
|
||||
p.major_id = object_id('Role')
|
||||
and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'CreateOrgCascadeId')
|
||||
and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'OrgCascadeId')
|
||||
)
|
||||
begin
|
||||
declare @CurrentUser sysname
|
||||
select @CurrentUser = user_name()
|
||||
execute sp_dropextendedproperty 'MS_Description',
|
||||
'user', @CurrentUser, 'table', 'Role', 'column', 'CreateOrgCascadeId'
|
||||
'user', @CurrentUser, 'table', 'Role', 'column', 'OrgCascadeId'
|
||||
|
||||
end
|
||||
|
||||
|
||||
select @CurrentUser = user_name()
|
||||
execute sp_addextendedproperty 'MS_Description',
|
||||
'创建人所属部门节点语义ID',
|
||||
'user', @CurrentUser, 'table', 'Role', 'column', 'CreateOrgCascadeId'
|
||||
'所属部门节点语义ID',
|
||||
'user', @CurrentUser, 'table', 'Role', 'column', 'OrgCascadeId'
|
||||
go
|
||||
|
||||
if exists(select 1 from sys.extended_properties p where
|
||||
p.major_id = object_id('Role')
|
||||
and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'OrgName')
|
||||
)
|
||||
begin
|
||||
declare @CurrentUser sysname
|
||||
select @CurrentUser = user_name()
|
||||
execute sp_dropextendedproperty 'MS_Description',
|
||||
'user', @CurrentUser, 'table', 'Role', 'column', 'OrgName'
|
||||
|
||||
end
|
||||
|
||||
|
||||
select @CurrentUser = user_name()
|
||||
execute sp_addextendedproperty 'MS_Description',
|
||||
'所属部门名称',
|
||||
'user', @CurrentUser, 'table', 'Role', 'column', 'OrgName'
|
||||
go
|
||||
|
||||
alter table Role
|
||||
@ -2217,6 +2256,25 @@ execute sp_addextendedproperty 'MS_Description',
|
||||
'user', @CurrentUser, 'table', 'UserOrg', 'column', 'Id'
|
||||
go
|
||||
|
||||
if exists(select 1 from sys.extended_properties p where
|
||||
p.major_id = object_id('UserOrg')
|
||||
and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'OrgId')
|
||||
)
|
||||
begin
|
||||
declare @CurrentUser sysname
|
||||
select @CurrentUser = user_name()
|
||||
execute sp_dropextendedproperty 'MS_Description',
|
||||
'user', @CurrentUser, 'table', 'UserOrg', 'column', 'OrgId'
|
||||
|
||||
end
|
||||
|
||||
|
||||
select @CurrentUser = user_name()
|
||||
execute sp_addextendedproperty 'MS_Description',
|
||||
'部门流水号',
|
||||
'user', @CurrentUser, 'table', 'UserOrg', 'column', 'OrgId'
|
||||
go
|
||||
|
||||
if exists(select 1 from sys.extended_properties p where
|
||||
p.major_id = object_id('UserOrg')
|
||||
and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'UserId')
|
||||
@ -2326,6 +2384,25 @@ execute sp_addextendedproperty 'MS_Description',
|
||||
'user', @CurrentUser, 'table', 'UserRole', 'column', 'Id'
|
||||
go
|
||||
|
||||
if exists(select 1 from sys.extended_properties p where
|
||||
p.major_id = object_id('UserRole')
|
||||
and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'RoleId')
|
||||
)
|
||||
begin
|
||||
declare @CurrentUser sysname
|
||||
select @CurrentUser = user_name()
|
||||
execute sp_dropextendedproperty 'MS_Description',
|
||||
'user', @CurrentUser, 'table', 'UserRole', 'column', 'RoleId'
|
||||
|
||||
end
|
||||
|
||||
|
||||
select @CurrentUser = user_name()
|
||||
execute sp_addextendedproperty 'MS_Description',
|
||||
'角色ID',
|
||||
'user', @CurrentUser, 'table', 'UserRole', 'column', 'RoleId'
|
||||
go
|
||||
|
||||
if exists(select 1 from sys.extended_properties p where
|
||||
p.major_id = object_id('UserRole')
|
||||
and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'UserId')
|
||||
@ -2386,3 +2463,4 @@ go
|
||||
alter table UserRole
|
||||
add constraint PK_USERROLE primary key (Id)
|
||||
go
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
16
OpenAuth.Domain/Interface/IRoleRepository.cs
Normal file
16
OpenAuth.Domain/Interface/IRoleRepository.cs
Normal file
@ -0,0 +1,16 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace OpenAuth.Domain.Interface
|
||||
{
|
||||
public interface IRoleRepository :IRepository<Role>
|
||||
{
|
||||
IEnumerable<Role> LoadRoles(int pageindex, int pagesize);
|
||||
|
||||
int GetRoleCntInOrgs(params int[] orgIds);
|
||||
IEnumerable<Role> LoadInOrgs(int pageindex, int pagesize, params int[] orgIds);
|
||||
|
||||
void Delete(int id);
|
||||
|
||||
}
|
||||
}
|
@ -44,6 +44,7 @@
|
||||
<ItemGroup>
|
||||
<Compile Include="Interface\IOrgRepository.cs" />
|
||||
<Compile Include="Interface\IRepository.cs" />
|
||||
<Compile Include="Interface\IRoleRepository.cs" />
|
||||
<Compile Include="Interface\IUserRepository.cs" />
|
||||
<Compile Include="Module.cs" />
|
||||
<Compile Include="ModuleElement.cs" />
|
||||
|
@ -17,7 +17,7 @@ namespace OpenAuth.Domain
|
||||
public int Id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 组织名称
|
||||
/// 名称
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public string Name { get; set; }
|
||||
@ -47,16 +47,22 @@ namespace OpenAuth.Domain
|
||||
public string CreateId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 创建人所属部门流水号
|
||||
/// 所属部门流水号
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public int CreateOrgId { get; set; }
|
||||
public int OrgId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 创建人所属部门节点语义ID
|
||||
/// 所属部门节点语义ID
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public string CreateOrgCascadeId { get; set; }
|
||||
public string OrgCascadeId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 所属部门名称
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public string OrgName { get; set; }
|
||||
|
||||
|
||||
public Role()
|
||||
@ -67,8 +73,9 @@ namespace OpenAuth.Domain
|
||||
this.Type= 0;
|
||||
this.CreateTime= DateTime.Now;
|
||||
this.CreateId= string.Empty;
|
||||
this.CreateOrgId= 0;
|
||||
this.CreateOrgCascadeId= string.Empty;
|
||||
this.OrgId= 0;
|
||||
this.OrgCascadeId= string.Empty;
|
||||
this.OrgName= string.Empty;
|
||||
}
|
||||
|
||||
|
||||
|
@ -12,12 +12,12 @@
|
||||
// <summary>IOC³õʼ»¯</summary>
|
||||
// ***********************************************************************
|
||||
|
||||
using System.Reflection;
|
||||
using System.Web.Mvc;
|
||||
using Autofac;
|
||||
using Autofac.Configuration;
|
||||
using Autofac.Integration.Mvc;
|
||||
using OpenAuth.App;
|
||||
using System.Reflection;
|
||||
using System.Web.Mvc;
|
||||
|
||||
namespace OpenAuth.Mvc
|
||||
{
|
||||
@ -27,12 +27,11 @@ namespace OpenAuth.Mvc
|
||||
{
|
||||
var builder = new ContainerBuilder();
|
||||
|
||||
builder.RegisterModule(new ConfigurationSettingsReader("autofac"));
|
||||
builder.RegisterModule(new ConfigurationSettingsReader("autofac"));
|
||||
builder.RegisterType<LoginApp>();
|
||||
builder.RegisterType<OrgManagerApp>();
|
||||
builder.RegisterType<UserManagerApp>();
|
||||
|
||||
|
||||
builder.RegisterType<RoleManagerApp>();
|
||||
// Register your MVC controllers.
|
||||
builder.RegisterControllers(typeof(MvcApplication).Assembly);
|
||||
|
||||
|
80
OpenAuth.Mvc/Controllers/RoleManagerController.cs
Normal file
80
OpenAuth.Mvc/Controllers/RoleManagerController.cs
Normal file
@ -0,0 +1,80 @@
|
||||
using System;
|
||||
using System.Web.Mvc;
|
||||
using Infrastructure;
|
||||
using OpenAuth.App;
|
||||
using OpenAuth.App.ViewModel;
|
||||
using OpenAuth.Domain;
|
||||
|
||||
namespace OpenAuth.Mvc.Controllers
|
||||
{
|
||||
public class RoleManagerController : BaseController
|
||||
{
|
||||
private RoleManagerApp _app;
|
||||
|
||||
public RoleManagerController()
|
||||
{
|
||||
_app = (RoleManagerApp)DependencyResolver.Current.GetService(typeof(RoleManagerApp));
|
||||
}
|
||||
|
||||
//
|
||||
// GET: /RoleManager/
|
||||
public ActionResult Index()
|
||||
{
|
||||
return View();
|
||||
}
|
||||
|
||||
public ActionResult Add(int id = 0)
|
||||
{
|
||||
return View(_app.Find(id));
|
||||
}
|
||||
|
||||
//添加或修改组织
|
||||
[HttpPost]
|
||||
public string Add(Role view)
|
||||
{
|
||||
try
|
||||
{
|
||||
_app.AddOrUpdate(view);
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
BjuiResponse.statusCode = "300";
|
||||
BjuiResponse.message = ex.Message;
|
||||
}
|
||||
return JsonHelper.Instance.Serialize(BjuiResponse);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 加载组织下面的所有用户
|
||||
/// </summary>
|
||||
public string Load(int orgId, int pageCurrent = 1, int pageSize = 30)
|
||||
{
|
||||
return JsonHelper.Instance.Serialize(_app.Load(orgId, pageCurrent, pageSize));
|
||||
}
|
||||
|
||||
//获取组织下面用户个数
|
||||
public int GetCount(int orgId)
|
||||
{
|
||||
return _app.GetRoleCntInOrg(orgId);
|
||||
}
|
||||
|
||||
public string Delete(string Id)
|
||||
{
|
||||
try
|
||||
{
|
||||
foreach (var obj in Id.Split(','))
|
||||
{
|
||||
_app.Delete(int.Parse(obj));
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
BjuiResponse.statusCode = "300";
|
||||
BjuiResponse.message = e.Message;
|
||||
}
|
||||
|
||||
return JsonHelper.Instance.Serialize(BjuiResponse);
|
||||
}
|
||||
}
|
||||
}
|
@ -127,6 +127,7 @@
|
||||
<Compile Include="Controllers\BaseController.cs" />
|
||||
<Compile Include="Controllers\HomeController.cs" />
|
||||
<Compile Include="Controllers\OrgManagerController.cs" />
|
||||
<Compile Include="Controllers\RoleManagerController.cs" />
|
||||
<Compile Include="Controllers\UserManagerController.cs" />
|
||||
<Compile Include="Global.asax.cs">
|
||||
<DependentUpon>Global.asax</DependentUpon>
|
||||
@ -617,6 +618,8 @@
|
||||
<Content Include="Views\OrgManager\LookupParent.cshtml" />
|
||||
<Content Include="Views\UserManager\Index.cshtml" />
|
||||
<Content Include="Views\UserManager\Add.cshtml" />
|
||||
<Content Include="Views\RoleManager\Add.cshtml" />
|
||||
<Content Include="Views\RoleManager\Index.cshtml" />
|
||||
</ItemGroup>
|
||||
<PropertyGroup>
|
||||
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
|
||||
|
@ -206,6 +206,7 @@
|
||||
<li data-id="99" data-pid="0" data-faicon="folder-open-o" data-faicon-close="folder-o">系统设置</li>
|
||||
<li data-id="100" data-pid="99" data-url="OrgManager/Index" data-tabid="orgManager" data-faicon="caret-right">机构管理</li>
|
||||
<li data-id="101" data-pid="99" data-url="UserManager/Index" data-tabid="userManager" data-faicon="caret-right">用户管理</li>
|
||||
<li data-id="102" data-pid="99" data-url="RoleManager/Index" data-tabid="roleManager" data-faicon="caret-right">角色管理</li>
|
||||
</ul>
|
||||
</div>
|
||||
</li>
|
||||
|
132
OpenAuth.Mvc/Views/RoleManager/Add.cshtml
Normal file
132
OpenAuth.Mvc/Views/RoleManager/Add.cshtml
Normal file
@ -0,0 +1,132 @@
|
||||
@model OpenAuth.Domain.Role
|
||||
@{
|
||||
ViewBag.Title = "title";
|
||||
Layout = null;
|
||||
}
|
||||
|
||||
<div class="bjui-pageContent">
|
||||
<form action="/RoleManager/Add" class="pageForm" data-toggle="validate">
|
||||
<table class="table table-condensed table-hover">
|
||||
<tbody>
|
||||
<tr>
|
||||
<td align="center"><h3>* 添加</h3></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
@Html.HiddenFor(m => m.Id)
|
||||
@Html.HiddenFor(m => m.CreateTime)
|
||||
<tr>
|
||||
<td>
|
||||
|
||||
<label for="Name" class="control-label x90">角色名称:</label>
|
||||
<input type="text" name="Name" id="Name" value="@Model.Name"
|
||||
data-rule="required" size="20">
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
|
||||
<label for="Status" class="control-label x90">当前状态:</label>
|
||||
<input type="text" name="Status" id="Status" value="@Model.Status"
|
||||
data-rule="required" size="20">
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
|
||||
<label for="Type" class="control-label x90">角色类型:</label>
|
||||
<input type="text" name="Type" id="Type" value="@Model.Type"
|
||||
data-rule="required" size="20">
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td>
|
||||
|
||||
<label for="CreateId" class="control-label x90">创建人ID:</label>
|
||||
<input type="text" name="CreateId" id="CreateId" value="@Model.CreateId"
|
||||
data-rule="required" size="20">
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td>
|
||||
<label for="OrgName" class="control-label x90">所属机构:</label>
|
||||
<input id="OrgId" name="OrgId" value="" style="display: none" />
|
||||
<input type="text" name="OrgName" id="OrgName"
|
||||
data-toggle="selectztree" size="20" data-tree="#j_select_tree1" value="">
|
||||
<ul id="j_select_tree1" class="ztree hide" data-toggle="ztree"></ul>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</form>
|
||||
</div>
|
||||
<div class="bjui-pageFooter">
|
||||
<ul>
|
||||
<li><button type="button" class="btn-close">关闭</button></li>
|
||||
<li><button type="submit" class="btn-green">保存</button></li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<script type="text/javascript">
|
||||
$(document).ready(function () {
|
||||
Init();
|
||||
});
|
||||
function Init() {
|
||||
var setting = {
|
||||
view: {
|
||||
selectedMulti: false
|
||||
},
|
||||
check: {
|
||||
enable: true,
|
||||
chkStyle: "checkbox",
|
||||
chkboxType: { "Y": "", "N": "" } //去掉勾选时级联
|
||||
},
|
||||
data: {
|
||||
key: {
|
||||
name: 'Name',
|
||||
title: 'Name'
|
||||
},
|
||||
simpleData: {
|
||||
enable: true,
|
||||
idKey: 'Id',
|
||||
pIdKey: 'ParentId',
|
||||
rootPId: 'null'
|
||||
}
|
||||
},
|
||||
callback: {
|
||||
onClick: zTreeOnClick,
|
||||
onCheck: zTreeCheck
|
||||
}
|
||||
};
|
||||
$.getJSON('OrgManager/LoadOrg', function (json) {
|
||||
var zTreeObj = $.fn.zTree.init($('#j_select_tree1'), setting, json);
|
||||
zTreeObj.expandAll(true);
|
||||
});
|
||||
}
|
||||
|
||||
function zTreeCheck(e, treeId, treeNode) {
|
||||
var zTree = $.fn.zTree.getZTreeObj(treeId),
|
||||
nodes = zTree.getCheckedNodes(true);
|
||||
var ids = '', names = '';
|
||||
for (var i = 0; i < nodes.length; i++) {
|
||||
ids += ',' + nodes[i].Id;
|
||||
names += ',' + nodes[i].Name;
|
||||
}
|
||||
if (ids.length > 0) { //去掉第一个逗号
|
||||
ids = ids.substr(1);
|
||||
names = names.substr(1);
|
||||
}
|
||||
|
||||
var $from = $('#' + treeId).data('fromObj');
|
||||
if ($from && $from.length) $from.val(names);
|
||||
|
||||
$('#OrganizationIds').val(ids);
|
||||
}
|
||||
function zTreeOnClick(event, treeId, treeNode) {
|
||||
var zTree = $.fn.zTree.getZTreeObj(treeId);
|
||||
zTree.checkNode(treeNode, !treeNode.checked, true, true);
|
||||
event.preventDefault();
|
||||
}
|
||||
</script>
|
175
OpenAuth.Mvc/Views/RoleManager/Index.cshtml
Normal file
175
OpenAuth.Mvc/Views/RoleManager/Index.cshtml
Normal file
@ -0,0 +1,175 @@
|
||||
@{
|
||||
string _prefix = "Role";
|
||||
var _treeId = _prefix + "Tree";
|
||||
var _gridId = _prefix + "Grid";
|
||||
var _treeDetail = _prefix + "Detail";
|
||||
}
|
||||
<div class="bjui-pageContent">
|
||||
<div class="clearfix">
|
||||
<div style="float: left; width: 220px; overflow: auto;" class="table table-bordered">
|
||||
<ul id="@_treeId" class="ztree"></ul>
|
||||
</div>
|
||||
|
||||
<div id="@_treeDetail" style="margin-left: 225px;">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<script type="text/javascript">
|
||||
var gridid = '#@_gridId';
|
||||
var selectedId = 0;
|
||||
$(document).ready(function () {
|
||||
initZtree();
|
||||
loadDataGrid();
|
||||
});
|
||||
//加载数据到datagrid
|
||||
function loadDataGrid() {
|
||||
//b-jui的datagrid需要重新处理HTML
|
||||
$('#@_treeDetail').empty()
|
||||
.append('<table id="@_gridId" class="table table-bordered"></table>');
|
||||
|
||||
$(gridid).datagrid({
|
||||
gridTitle: '列表',
|
||||
showToolbar: true,
|
||||
filterThead: false,
|
||||
toolbarItem: 'refresh, |, del',
|
||||
toolbarCustom: '<a href="/RoleManager/Add" class="btn btn-green" data-icon ="plus" ' +
|
||||
'data-toggle="dialog" data-id="dialog-mask" data-mask="true" data-on-close="refreshGrid">添加</a>' +
|
||||
'<button class=" btn-green" onclick="editRole()" data-icon="pencil" type="button">编辑</button>',
|
||||
columns: [
|
||||
{
|
||||
name: 'Id',
|
||||
label: '流水号'
|
||||
, hide: true
|
||||
},
|
||||
{
|
||||
name: 'Name',
|
||||
label: '角色名称'
|
||||
},
|
||||
{
|
||||
name: 'Status',
|
||||
label: '当前状态'
|
||||
},
|
||||
{
|
||||
name: 'Type',
|
||||
label: '角色类型'
|
||||
},
|
||||
{
|
||||
name: 'CreateTime',
|
||||
label: '创建时间'
|
||||
, type: 'date',
|
||||
width: 180,
|
||||
pattern: 'yyyy-MM-dd HH:mm:ss'
|
||||
},
|
||||
{
|
||||
name: 'CreateId',
|
||||
label: '创建人ID'
|
||||
},
|
||||
{
|
||||
name: 'OrgId',
|
||||
label: '所属部门流水号'
|
||||
},
|
||||
{
|
||||
name: 'OrgCascadeId',
|
||||
label: '所属部门节点语义ID'
|
||||
},
|
||||
{
|
||||
name: 'OrgName',
|
||||
label: '所属部门名称'
|
||||
},
|
||||
],
|
||||
// data: data,
|
||||
dataUrl: 'RoleManager/Load?orgId=' + selectedId,
|
||||
delUrl: 'Role/Delete',
|
||||
delPK: "Id",
|
||||
fullGrid: true,
|
||||
showLinenumber: true,
|
||||
showCheckboxcol: true,
|
||||
paging: true,
|
||||
filterMult: false,
|
||||
showTfoot: true,
|
||||
height: '700',
|
||||
delCallback: function (delResult) {
|
||||
if (delResult.statusCode == "200")
|
||||
loadDataGrid();
|
||||
else {
|
||||
$(this).alertmsg('warn', delResult.message);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function zTreeOnClick(event, treeId, treeNode) {
|
||||
selectedId = treeNode.Id;
|
||||
loadDataGrid();
|
||||
}
|
||||
|
||||
function initZtree() {
|
||||
var setting = {
|
||||
view: {selectedMulti: false},
|
||||
data: {
|
||||
key: {
|
||||
name: 'Name',
|
||||
title: 'Name'
|
||||
},
|
||||
simpleData: {
|
||||
enable: true,
|
||||
idKey: 'Id',
|
||||
pIdKey: 'ParentId',
|
||||
rootPId: 'null'
|
||||
}
|
||||
},
|
||||
callback: {onClick: zTreeOnClick}
|
||||
};
|
||||
$.getJSON('OrgManager/LoadOrg', function (json) {
|
||||
var zTreeObj = $.fn.zTree.init($('#@_treeId'), setting, json);
|
||||
zTreeObj.expandAll(true);
|
||||
});
|
||||
}
|
||||
|
||||
//获取勾选的值
|
||||
//column:为从0开始的列标识
|
||||
function getSelected(column) {
|
||||
var selected = $(gridid).data('selectedTrs');
|
||||
if (selected == null || selected.length == 0) {
|
||||
$(this).alertmsg('warn', '至少选择一个对象', {
|
||||
displayMode: 'slide',
|
||||
title: '重要提示'
|
||||
});
|
||||
return null;
|
||||
}
|
||||
|
||||
//todo:下面这段只能chrome有效
|
||||
var records = new Array();
|
||||
selected.each(function () {
|
||||
records[records.length] = this.children[column].innerText;
|
||||
});
|
||||
|
||||
return records[0];
|
||||
}
|
||||
|
||||
|
||||
|
||||
//自定义的编辑按钮
|
||||
function editRole() {
|
||||
var selected = getSelected(2);
|
||||
if (selected == null) return;
|
||||
|
||||
$(this).dialog({
|
||||
id: 'editDialog',
|
||||
url: '/RoleManager/Add?id=' + selected,
|
||||
title: '编辑',
|
||||
onClose:function() {
|
||||
refreshGrid();
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
function refreshGrid() {
|
||||
$('#@_gridId').datagrid('refresh');
|
||||
// loadDataGrid();
|
||||
}
|
||||
//@@ sourceURL=RoleManagerIndex.js
|
||||
</script>
|
@ -1,130 +1,130 @@
|
||||
@model OpenAuth.App.ViewModel.UserView
|
||||
@{
|
||||
ViewBag.Title = "title";
|
||||
Layout = null;
|
||||
}
|
||||
|
||||
<div class="bjui-pageContent">
|
||||
<form action="/UserManager/Add" class="pageForm" data-toggle="validate">
|
||||
<table class="table table-condensed table-hover">
|
||||
<tbody>
|
||||
<tr>
|
||||
<td align="center"><h3>* 添加</h3></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
@Html.HiddenFor(m =>m.CreateTime)
|
||||
@Html.HiddenFor(m =>m.Id)
|
||||
<label for="Account" class="control-label x90">用户账号:</label>
|
||||
<input type="text" name="Account" id="Account" value="@Model.Account"
|
||||
data-rule="required" size="20">
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<label for="Name" class="control-label x90">姓名/昵称:</label>
|
||||
<input type="text" name="Name" id="Name" value="@Model.Name" size="20">
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<label for="Organizations" class="control-label x90">所属机构:</label>
|
||||
<input id="OrganizationIds" name="OrganizationIds" value="@Model.OrganizationIds" style="display: none" />
|
||||
<input type="text" name="Organizations" id="Organizations"
|
||||
data-toggle="selectztree" size="20" data-tree="#j_select_tree1" value="@Model.Organizations">
|
||||
<ul id="j_select_tree1" class="ztree hide" data-toggle="ztree" >
|
||||
</ul>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<label for="Status" class="control-label x85">设置状态:</label>
|
||||
|
||||
<select name="Status" id="Status" data-toggle="selectpicker" data-rule="required">
|
||||
<option value="0">正常</option>
|
||||
<option value="1">禁用</option>
|
||||
</select>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<label for="Sex" class="control-label x85">性别:</label>
|
||||
|
||||
<select name="Sex" id="Sex" data-toggle="selectpicker" data-rule="required">
|
||||
<option value="0">男</option>
|
||||
<option value="1">女</option>
|
||||
</select>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</form>
|
||||
</div>
|
||||
<div class="bjui-pageFooter">
|
||||
<ul>
|
||||
<li><button type="button" class="btn-close">关闭</button></li>
|
||||
<li><button type="submit" class="btn-green">保存</button></li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<script type="text/javascript">
|
||||
$(document).ready(function () {
|
||||
Init();
|
||||
});
|
||||
function Init() {
|
||||
var setting = {
|
||||
view: {
|
||||
selectedMulti: false
|
||||
},
|
||||
check: {
|
||||
enable: true,
|
||||
chkStyle: "checkbox",
|
||||
chkboxType: { "Y": "", "N": "" } //去掉勾选时级联
|
||||
},
|
||||
data: {
|
||||
key: {
|
||||
name: 'Name',
|
||||
title: 'Name'
|
||||
},
|
||||
simpleData: {
|
||||
enable: true,
|
||||
idKey: 'Id',
|
||||
pIdKey: 'ParentId',
|
||||
rootPId: 'null'
|
||||
}
|
||||
},
|
||||
callback: {
|
||||
onClick: zTreeOnClick,
|
||||
onCheck: zTreeCheck
|
||||
}
|
||||
};
|
||||
$.getJSON('OrgManager/LoadOrg', function (json) {
|
||||
var zTreeObj = $.fn.zTree.init($('#j_select_tree1'), setting, json);
|
||||
zTreeObj.expandAll(true);
|
||||
});
|
||||
}
|
||||
|
||||
function zTreeCheck(e, treeId, treeNode) {
|
||||
var zTree = $.fn.zTree.getZTreeObj(treeId),
|
||||
nodes = zTree.getCheckedNodes(true);
|
||||
var ids = '', names = '';
|
||||
for (var i = 0; i < nodes.length; i++) {
|
||||
ids += ',' + nodes[i].Id;
|
||||
names += ',' + nodes[i].Name;
|
||||
}
|
||||
if (ids.length > 0) { //去掉第一个逗号
|
||||
ids = ids.substr(1);
|
||||
names = names.substr(1);
|
||||
}
|
||||
|
||||
var $from = $('#' + treeId).data('fromObj');
|
||||
if ($from && $from.length) $from.val(names);
|
||||
|
||||
$('#OrganizationIds').val(ids);
|
||||
}
|
||||
function zTreeOnClick(event, treeId, treeNode) {
|
||||
var zTree = $.fn.zTree.getZTreeObj(treeId);
|
||||
zTree.checkNode(treeNode, !treeNode.checked, true, true);
|
||||
event.preventDefault();
|
||||
}
|
||||
@model OpenAuth.App.ViewModel.UserView
|
||||
@{
|
||||
ViewBag.Title = "title";
|
||||
Layout = null;
|
||||
}
|
||||
|
||||
<div class="bjui-pageContent">
|
||||
<form action="/UserManager/Add" class="pageForm" data-toggle="validate">
|
||||
<table class="table table-condensed table-hover">
|
||||
<tbody>
|
||||
<tr>
|
||||
<td align="center"><h3>* 添加</h3></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
@Html.HiddenFor(m =>m.CreateTime)
|
||||
@Html.HiddenFor(m =>m.Id)
|
||||
<label for="Account" class="control-label x90">用户账号:</label>
|
||||
<input type="text" name="Account" id="Account" value="@Model.Account"
|
||||
data-rule="required" size="20">
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<label for="Name" class="control-label x90">姓名/昵称:</label>
|
||||
<input type="text" name="Name" id="Name" value="@Model.Name" size="20">
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<label for="Organizations" class="control-label x90">所属机构:</label>
|
||||
<input id="OrganizationIds" name="OrganizationIds" value="@Model.OrganizationIds" style="display: none" />
|
||||
<input type="text" name="Organizations" id="Organizations"
|
||||
data-toggle="selectztree" size="20" data-tree="#j_select_tree1" value="@Model.Organizations">
|
||||
<ul id="j_select_tree1" class="ztree hide" data-toggle="ztree" >
|
||||
</ul>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<label for="Status" class="control-label x85">设置状态:</label>
|
||||
|
||||
<select name="Status" id="Status" data-toggle="selectpicker" data-rule="required">
|
||||
<option value="0">正常</option>
|
||||
<option value="1">禁用</option>
|
||||
</select>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<label for="Sex" class="control-label x85">性别:</label>
|
||||
|
||||
<select name="Sex" id="Sex" data-toggle="selectpicker" data-rule="required">
|
||||
<option value="0">男</option>
|
||||
<option value="1">女</option>
|
||||
</select>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</form>
|
||||
</div>
|
||||
<div class="bjui-pageFooter">
|
||||
<ul>
|
||||
<li><button type="button" class="btn-close">关闭</button></li>
|
||||
<li><button type="submit" class="btn-green">保存</button></li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<script type="text/javascript">
|
||||
$(document).ready(function () {
|
||||
Init();
|
||||
});
|
||||
function Init() {
|
||||
var setting = {
|
||||
view: {
|
||||
selectedMulti: false
|
||||
},
|
||||
check: {
|
||||
enable: true,
|
||||
chkStyle: "checkbox",
|
||||
chkboxType: { "Y": "", "N": "" } //去掉勾选时级联
|
||||
},
|
||||
data: {
|
||||
key: {
|
||||
name: 'Name',
|
||||
title: 'Name'
|
||||
},
|
||||
simpleData: {
|
||||
enable: true,
|
||||
idKey: 'Id',
|
||||
pIdKey: 'ParentId',
|
||||
rootPId: 'null'
|
||||
}
|
||||
},
|
||||
callback: {
|
||||
onClick: zTreeOnClick,
|
||||
onCheck: zTreeCheck
|
||||
}
|
||||
};
|
||||
$.getJSON('OrgManager/LoadOrg', function (json) {
|
||||
var zTreeObj = $.fn.zTree.init($('#j_select_tree1'), setting, json);
|
||||
zTreeObj.expandAll(true);
|
||||
});
|
||||
}
|
||||
|
||||
function zTreeCheck(e, treeId, treeNode) {
|
||||
var zTree = $.fn.zTree.getZTreeObj(treeId),
|
||||
nodes = zTree.getCheckedNodes(true);
|
||||
var ids = '', names = '';
|
||||
for (var i = 0; i < nodes.length; i++) {
|
||||
ids += ',' + nodes[i].Id;
|
||||
names += ',' + nodes[i].Name;
|
||||
}
|
||||
if (ids.length > 0) { //去掉第一个逗号
|
||||
ids = ids.substr(1);
|
||||
names = names.substr(1);
|
||||
}
|
||||
|
||||
var $from = $('#' + treeId).data('fromObj');
|
||||
if ($from && $from.length) $from.val(names);
|
||||
|
||||
$('#OrganizationIds').val(ids);
|
||||
}
|
||||
function zTreeOnClick(event, treeId, treeNode) {
|
||||
var zTree = $.fn.zTree.getZTreeObj(treeId);
|
||||
zTree.checkNode(treeNode, !treeNode.checked, true, true);
|
||||
event.preventDefault();
|
||||
}
|
||||
</script>
|
@ -174,8 +174,8 @@
|
||||
}
|
||||
|
||||
function refreshGrid() {
|
||||
//grid.refresh();
|
||||
loadDataGrid();
|
||||
$('#@_gridId').datagrid('refresh');
|
||||
// loadDataGrid();
|
||||
}
|
||||
//@@ sourceURL=userManagerIndex.js
|
||||
</script>
|
||||
|
@ -41,6 +41,7 @@
|
||||
<components>
|
||||
<component type=" OpenAuth.Repository.UserRepository" service=" OpenAuth.Domain.Interface.IUserRepository,OpenAuth.Domain" />
|
||||
<component type=" OpenAuth.Repository.OrgRepository" service="OpenAuth.Domain.Interface.IOrgRepository,OpenAuth.Domain" />
|
||||
<component type=" OpenAuth.Repository.RoleRepository" service="OpenAuth.Domain.Interface.IRoleRepository,OpenAuth.Domain" />
|
||||
</components>
|
||||
</autofac>
|
||||
|
||||
|
@ -20,7 +20,11 @@ namespace OpenAuth.Repository.Models.Mapping
|
||||
.IsRequired()
|
||||
.HasMaxLength(64);
|
||||
|
||||
this.Property(t => t.CreateOrgCascadeId)
|
||||
this.Property(t => t.OrgCascadeId)
|
||||
.IsRequired()
|
||||
.HasMaxLength(255);
|
||||
|
||||
this.Property(t => t.OrgName)
|
||||
.IsRequired()
|
||||
.HasMaxLength(255);
|
||||
|
||||
@ -32,8 +36,9 @@ namespace OpenAuth.Repository.Models.Mapping
|
||||
this.Property(t => t.Type).HasColumnName("Type");
|
||||
this.Property(t => t.CreateTime).HasColumnName("CreateTime");
|
||||
this.Property(t => t.CreateId).HasColumnName("CreateId");
|
||||
this.Property(t => t.CreateOrgId).HasColumnName("CreateOrgId");
|
||||
this.Property(t => t.CreateOrgCascadeId).HasColumnName("CreateOrgCascadeId");
|
||||
this.Property(t => t.OrgId).HasColumnName("OrgId");
|
||||
this.Property(t => t.OrgCascadeId).HasColumnName("OrgCascadeId");
|
||||
this.Property(t => t.OrgName).HasColumnName("OrgName");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -69,6 +69,7 @@
|
||||
<Compile Include="Models\OpenAuthDBContext.cs" />
|
||||
<Compile Include="OrgRepository.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="RoleRepository.cs" />
|
||||
<Compile Include="UserRepository.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
|
41
OpenAuth.Repository/RoleRepository.cs
Normal file
41
OpenAuth.Repository/RoleRepository.cs
Normal file
@ -0,0 +1,41 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using OpenAuth.Domain;
|
||||
using OpenAuth.Domain.Interface;
|
||||
|
||||
namespace OpenAuth.Repository
|
||||
{
|
||||
public class RoleRepository :BaseRepository<Role>, IRoleRepository
|
||||
{
|
||||
public IEnumerable<Role> LoadRoles(int pageindex, int pagesize)
|
||||
{
|
||||
return Context.Roles.OrderBy(u => u.Name).Skip((pageindex - 1) * pagesize).Take(pagesize);
|
||||
}
|
||||
|
||||
public int GetRoleCntInOrgs(params int[] orgIds)
|
||||
{
|
||||
return LoadInOrgs(orgIds).Count();
|
||||
}
|
||||
|
||||
public IEnumerable<Role> LoadInOrgs(int pageindex, int pagesize, params int[] orgIds)
|
||||
{
|
||||
return LoadInOrgs(orgIds).OrderBy(u => u.Name).Skip((pageindex - 1) * pagesize).Take(pagesize);
|
||||
}
|
||||
|
||||
public void Delete(int id)
|
||||
{
|
||||
Delete(u =>u.Id == id);
|
||||
}
|
||||
|
||||
public IEnumerable<Role> LoadInOrgs(params int[] orgId)
|
||||
{
|
||||
var result = from role in Context.Roles.Where(u => orgId.Contains(u.OrgId)) select role;
|
||||
|
||||
return result;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
@ -66,6 +66,7 @@
|
||||
<ItemGroup>
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="TestFunction.cs" />
|
||||
<Compile Include="TestRoleApp.cs" />
|
||||
<Compile Include="TestUserApp.cs" />
|
||||
<Compile Include="TestOrgApp.cs" />
|
||||
</ItemGroup>
|
||||
|
79
OpenAuth.UnitTest/TestRoleApp.cs
Normal file
79
OpenAuth.UnitTest/TestRoleApp.cs
Normal file
@ -0,0 +1,79 @@
|
||||
using System;
|
||||
using System.Text;
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using OpenAuth.App;
|
||||
using OpenAuth.App.ViewModel;
|
||||
using OpenAuth.Domain;
|
||||
using OpenAuth.Repository;
|
||||
|
||||
namespace OpenAuth.UnitTest
|
||||
{
|
||||
/// <summary>
|
||||
/// TestOrgApp 的摘要说明
|
||||
/// </summary>
|
||||
[TestClass]
|
||||
public class TestRoleApp
|
||||
{
|
||||
|
||||
private RoleManagerApp _app = new RoleManagerApp(new RoleRepository(), new OrgRepository());
|
||||
private string _time = DateTime.Now.ToString("HH_mm_ss_ms");
|
||||
|
||||
|
||||
[TestMethod]
|
||||
public void TestAdd()
|
||||
{
|
||||
for (int i = 0; i < 30; i++)
|
||||
{
|
||||
Add();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void TestDel()
|
||||
{
|
||||
var role = new Role
|
||||
{
|
||||
Name = "即将删除" + _time,
|
||||
CreateTime = DateTime.Now,
|
||||
OrgId = 1
|
||||
};
|
||||
_app.AddOrUpdate(role);
|
||||
Console.WriteLine("new role:" + role.Id);
|
||||
_app.Delete(role.Id);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
[TestMethod]
|
||||
public void TestLoad()
|
||||
{
|
||||
var users = _app.Load(1,1, 10);
|
||||
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void TestEdit()
|
||||
{
|
||||
var role = Add();
|
||||
role.Name = "修改后的名称" + _time;
|
||||
_app.AddOrUpdate(role);
|
||||
Console.WriteLine(role.Name);
|
||||
}
|
||||
|
||||
|
||||
private Role Add()
|
||||
{
|
||||
var role = new Role
|
||||
{
|
||||
Name = "test_" + _time,
|
||||
CreateTime = DateTime.Now,
|
||||
OrgId = 1
|
||||
};
|
||||
_app.AddOrUpdate(role);
|
||||
return role;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,83 +1,83 @@
|
||||
using System;
|
||||
using System.Text;
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using OpenAuth.App;
|
||||
using OpenAuth.App.ViewModel;
|
||||
using OpenAuth.Domain;
|
||||
using OpenAuth.Repository;
|
||||
|
||||
namespace OpenAuth.UnitTest
|
||||
{
|
||||
/// <summary>
|
||||
/// TestOrgApp 的摘要说明
|
||||
/// </summary>
|
||||
[TestClass]
|
||||
public class TestUserApp
|
||||
{
|
||||
|
||||
private UserManagerApp _app = new UserManagerApp(new UserRepository(), new OrgRepository());
|
||||
private string _time = DateTime.Now.ToString("HH_mm_ss_ms");
|
||||
|
||||
|
||||
[TestMethod]
|
||||
public void TestAdd()
|
||||
{
|
||||
for (int i = 0; i < 30; i++)
|
||||
{
|
||||
Add();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void TestDel()
|
||||
{
|
||||
var user = new UserView
|
||||
{
|
||||
Account = "user" + _time,
|
||||
Name = "即将被删除的账号" + _time,
|
||||
OrganizationIds = "3,2"
|
||||
|
||||
};
|
||||
_app.AddOrUpdate(user);
|
||||
Console.WriteLine("new user:" + user.Id);
|
||||
_app.Delete(user.Id);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
[TestMethod]
|
||||
public void TestLoad()
|
||||
{
|
||||
var users = _app.Load(1,1, 10);
|
||||
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void TestEdit()
|
||||
{
|
||||
var user = Add();
|
||||
user.Name = "修改后的名称" + _time;
|
||||
_app.AddOrUpdate(user);
|
||||
Console.WriteLine(user.Name);
|
||||
}
|
||||
|
||||
|
||||
private UserView Add()
|
||||
{
|
||||
var user = new UserView
|
||||
{
|
||||
Account = "user" + _time,
|
||||
Name = "新用户" + _time,
|
||||
OrganizationIds = "3,2"
|
||||
|
||||
};
|
||||
_app.AddOrUpdate(user);
|
||||
Console.WriteLine(user.Name + " \t用户ID:" + user.Id);
|
||||
return user;
|
||||
}
|
||||
}
|
||||
}
|
||||
using System;
|
||||
using System.Text;
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using OpenAuth.App;
|
||||
using OpenAuth.App.ViewModel;
|
||||
using OpenAuth.Domain;
|
||||
using OpenAuth.Repository;
|
||||
|
||||
namespace OpenAuth.UnitTest
|
||||
{
|
||||
/// <summary>
|
||||
/// TestOrgApp 的摘要说明
|
||||
/// </summary>
|
||||
[TestClass]
|
||||
public class TestUserApp
|
||||
{
|
||||
|
||||
private UserManagerApp _app = new UserManagerApp(new UserRepository(), new OrgRepository());
|
||||
private string _time = DateTime.Now.ToString("HH_mm_ss_ms");
|
||||
|
||||
|
||||
[TestMethod]
|
||||
public void TestAdd()
|
||||
{
|
||||
for (int i = 0; i < 30; i++)
|
||||
{
|
||||
Add();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void TestDel()
|
||||
{
|
||||
var user = new UserView
|
||||
{
|
||||
Account = "user" + _time,
|
||||
Name = "即将被删除的账号" + _time,
|
||||
OrganizationIds = "3,2"
|
||||
|
||||
};
|
||||
_app.AddOrUpdate(user);
|
||||
Console.WriteLine("new user:" + user.Id);
|
||||
_app.Delete(user.Id);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
[TestMethod]
|
||||
public void TestLoad()
|
||||
{
|
||||
var users = _app.Load(1,1, 10);
|
||||
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void TestEdit()
|
||||
{
|
||||
var user = Add();
|
||||
user.Name = "修改后的名称" + _time;
|
||||
_app.AddOrUpdate(user);
|
||||
Console.WriteLine(user.Name);
|
||||
}
|
||||
|
||||
|
||||
private UserView Add()
|
||||
{
|
||||
var user = new UserView
|
||||
{
|
||||
Account = "user" + _time,
|
||||
Name = "新用户" + _time,
|
||||
OrganizationIds = "3,2"
|
||||
|
||||
};
|
||||
_app.AddOrUpdate(user);
|
||||
Console.WriteLine(user.Name + " \t用户ID:" + user.Id);
|
||||
return user;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user