mirror of
https://gitee.com/dotnetchina/OpenAuth.Net.git
synced 2025-07-15 14:04:41 +08:00
添加资源中心,为数据字段授权、第三方网站授权做准备
This commit is contained in:
parent
01f130be1b
commit
b8fb3f7a2d
@ -1,30 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<codeSmith xmlns="http://www.codesmithtools.com/schema/csp.xsd">
|
||||
<variables>
|
||||
<add key="ConnectionString1" value="Data Source=.;Initial Catalog=OpenAuthDB;Persist Security Info=True;User ID=sa;Password=000000;MultipleActiveResultSets=True" />
|
||||
</variables>
|
||||
<propertySets>
|
||||
<propertySet name="Module.Index.cshtml" output="..\bin\ModuleManager\Index.cshtml" template="cshtmlwithorg.cst" mergeInit="Data Source=.;Initial Catalog=OpenAuthDB;Persist Security Info=True;User ID=sa;Password=000000;MultipleActiveResultSets=True">
|
||||
<property name="SourceTable">
|
||||
<connectionString>$(ConnectionString1)</connectionString>
|
||||
<providerType>SchemaExplorer.SqlSchemaProvider,SchemaExplorer.SqlSchemaProvider</providerType>
|
||||
<table>
|
||||
<owner>dbo</owner>
|
||||
<name>Module</name>
|
||||
</table>
|
||||
</property>
|
||||
<property name="ModuleName">Module</property>
|
||||
</propertySet>
|
||||
<propertySet name="Role.Index.cshtml" output="..\bin\RoleManager\Index.cshtml" template="cshtmlwithorg.cst">
|
||||
<property name="SourceTable">
|
||||
<connectionString>$(ConnectionString1)</connectionString>
|
||||
<providerType>SchemaExplorer.SqlSchemaProvider,SchemaExplorer.SqlSchemaProvider</providerType>
|
||||
<table>
|
||||
<owner>dbo</owner>
|
||||
<name>Role</name>
|
||||
</table>
|
||||
</property>
|
||||
<property name="ModuleName">Role</property>
|
||||
</propertySet>
|
||||
</propertySets>
|
||||
</codeSmith>
|
@ -1,145 +1,145 @@
|
||||
<%--
|
||||
Name: Database Table Properties
|
||||
Author: Paul Welter
|
||||
Description: Create a list of properties from a database table
|
||||
--%>
|
||||
<%@ CodeTemplate Language="C#" TargetLanguage="C#" Debug="False" Encoding="utf-8" Description="添加模块" %>
|
||||
<%@ Property Name="SourceTable" Type="SchemaExplorer.TableSchema" Category="Context"
|
||||
Description="连接的数据库" %>
|
||||
<%@ Property Name="ModuleName" Type="String" Category="Context" Description="模块名称" %>
|
||||
<%@ Property Name="NeedViewModel" Type="Boolean" Category="Context" Default="False" Description="是否需要ViewModel" %>
|
||||
<%@ Property Name="CascadeId" Type="String" Category="" Default="ParentId" Description="级联字段" %>
|
||||
<%@ Property Name="CascadeName" Type="String" Category="" Default="ParentName" Description="级联显示的文字" %>
|
||||
<%@ Map Name="CSharpAlias" Src="System-CSharpAlias" Description="System to C# Type Map" %>
|
||||
<%@ Assembly Name="SchemaExplorer" %>
|
||||
<%@ Import Namespace="SchemaExplorer" %>
|
||||
<script runat="template">
|
||||
public String GetModelName()
|
||||
{
|
||||
if(NeedViewModel)
|
||||
return ModuleName +"View";
|
||||
else
|
||||
return ModuleName;
|
||||
}
|
||||
</script>
|
||||
<%if(NeedViewModel){ %>
|
||||
@model OpenAuth.App.ViewModel.<%=GetModelName()%>
|
||||
<%} else{ %>
|
||||
@model OpenAuth.Domain.<%=GetModelName()%>
|
||||
<%} %>
|
||||
@{
|
||||
ViewBag.Title = "<%=GetModelName()%>编辑界面";
|
||||
Layout = null;
|
||||
}
|
||||
|
||||
<div class="bjui-pageContent">
|
||||
<form action="/<%=ModuleName%>Manager/Add" class="pageForm" data-toggle="validate">
|
||||
<table class="table table-condensed table-hover">
|
||||
<tbody>
|
||||
<% foreach (ColumnSchema column in this.SourceTable.Columns) {
|
||||
if(column.Name == CascadeName) continue;
|
||||
%>
|
||||
<tr>
|
||||
<td>
|
||||
<%if(column.IsPrimaryKeyMember){ %>
|
||||
@Html.HiddenFor(m =>m.Id)
|
||||
<% } else if(column.Name == CascadeId) {%>
|
||||
<label for="<%=column.Name%>" class="control-label x85"><%=column.Description%>:</label>
|
||||
<input id="<%=column.Name%>" name="<%=column.Name%>" value="" style="display: none"/>
|
||||
<input type="text" name="<%=CascadeName%>" id="<%=CascadeName%>"
|
||||
data-toggle="selectztree" size="20" data-tree="#j_select_tree1" value="@Model.<%=CascadeName%>">
|
||||
<ul id="j_select_tree1" class="ztree hide" data-toggle="ztree"></ul>
|
||||
|
||||
<% } else if(CSharpAlias[column.SystemType.FullName] == "bool") {%>
|
||||
<label for="<%=column.Name%>" class="control-label x85"><%=column.Description%>:</label>
|
||||
|
||||
<select name="<%=column.Name%>" id="<%=column.Name%>" data-toggle="selectpicker" data-rule="required">
|
||||
<option value="0" @if (Model.<%=column.Name%>) { <text> selected="selected" </text> }>否</option>
|
||||
<option value="1" @if (!Model.<%=column.Name%>) { <text> selected="selected" </text> }>是</option>
|
||||
</select>
|
||||
<%} else if(CSharpAlias[column.SystemType.FullName] == "int") {%>
|
||||
<label for="<%=column.Name%>" class="control-label x85"><%=column.Description%>:</label>
|
||||
<select name="<%=column.Name%>" id="<%=column.Name%>" data-toggle="selectpicker" data-rule="required">
|
||||
<option value="0" @if (Model.<%=column.Name%> == 0) { <text> selected="selected" </text> }>默认</option>
|
||||
<option value="1" @if (Model.<%=column.Name%> == 1) { <text> selected="selected" </text> }>状态1</option>
|
||||
</select>
|
||||
<%} else{%>
|
||||
<label for="<%=column.Name%>" class="control-label x90"><%=column.Description%>:</label>
|
||||
<input type="text" name="<%=column.Name%>" id="<%=column.Name%>" value="@Model.<%=column.Name%>"
|
||||
data-rule="required" size="20">
|
||||
<%} %>
|
||||
</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);
|
||||
|
||||
$('#<%=CascadeId%>').val(ids);
|
||||
}
|
||||
function zTreeOnClick(event, treeId, treeNode) {
|
||||
var zTree = $.fn.zTree.getZTreeObj(treeId);
|
||||
zTree.checkNode(treeNode, !treeNode.checked, true, true);
|
||||
event.preventDefault();
|
||||
}
|
||||
<%--
|
||||
Name: Database Table Properties
|
||||
Author: Paul Welter
|
||||
Description: Create a list of properties from a database table
|
||||
--%>
|
||||
<%@ CodeTemplate Language="C#" TargetLanguage="C#" Debug="False" Encoding="utf-8" Description="添加模块" %>
|
||||
<%@ Property Name="SourceTable" Type="SchemaExplorer.TableSchema" Category="Context"
|
||||
Description="连接的数据库" %>
|
||||
<%@ Property Name="ModuleName" Type="String" Category="Context" Description="模块名称" %>
|
||||
<%@ Property Name="NeedViewModel" Type="Boolean" Category="Context" Default="False" Description="是否需要ViewModel" %>
|
||||
<%@ Property Name="CascadeId" Type="String" Category="" Default="ParentId" Description="级联字段" %>
|
||||
<%@ Property Name="CascadeName" Type="String" Category="" Default="ParentName" Description="级联显示的文字" %>
|
||||
<%@ Map Name="CSharpAlias" Src="System-CSharpAlias" Description="System to C# Type Map" %>
|
||||
<%@ Assembly Name="SchemaExplorer" %>
|
||||
<%@ Import Namespace="SchemaExplorer" %>
|
||||
<script runat="template">
|
||||
public String GetModelName()
|
||||
{
|
||||
if(NeedViewModel)
|
||||
return ModuleName +"View";
|
||||
else
|
||||
return ModuleName;
|
||||
}
|
||||
</script>
|
||||
<%if(NeedViewModel){ %>
|
||||
@model OpenAuth.App.ViewModel.<%=GetModelName()%>
|
||||
<%} else{ %>
|
||||
@model OpenAuth.Domain.<%=GetModelName()%>
|
||||
<%} %>
|
||||
@{
|
||||
ViewBag.Title = "<%=GetModelName()%>编辑界面";
|
||||
Layout = null;
|
||||
}
|
||||
|
||||
<div class="bjui-pageContent">
|
||||
<form action="/<%=ModuleName%>Manager/Add" class="pageForm" data-toggle="validate">
|
||||
<table class="table table-condensed table-hover">
|
||||
<tbody>
|
||||
<% foreach (ColumnSchema column in this.SourceTable.Columns) {
|
||||
if(column.Name == CascadeName) continue;
|
||||
%>
|
||||
<tr>
|
||||
<td>
|
||||
<%if(column.IsPrimaryKeyMember){ %>
|
||||
@Html.HiddenFor(m =>m.Id)
|
||||
<% } else if(column.Name == CascadeId) {%>
|
||||
<label for="<%=column.Name%>" class="control-label x85"><%=column.Description%>:</label>
|
||||
<input id="<%=column.Name%>" name="<%=column.Name%>" value="" style="display: none"/>
|
||||
<input type="text" name="<%=CascadeName%>" id="<%=CascadeName%>"
|
||||
data-toggle="selectztree" size="20" data-tree="#j_select_tree1" value="@Model.<%=CascadeName%>">
|
||||
<ul id="j_select_tree1" class="ztree hide" data-toggle="ztree"></ul>
|
||||
|
||||
<% } else if(CSharpAlias[column.SystemType.FullName] == "bool") {%>
|
||||
<label for="<%=column.Name%>" class="control-label x85"><%=column.Description%>:</label>
|
||||
|
||||
<select name="<%=column.Name%>" id="<%=column.Name%>" data-toggle="selectpicker" data-rule="required">
|
||||
<option value="0" @if (Model.<%=column.Name%>) { <text> selected="selected" </text> }>否</option>
|
||||
<option value="1" @if (!Model.<%=column.Name%>) { <text> selected="selected" </text> }>是</option>
|
||||
</select>
|
||||
<%} else if(CSharpAlias[column.SystemType.FullName] == "int") {%>
|
||||
<label for="<%=column.Name%>" class="control-label x85"><%=column.Description%>:</label>
|
||||
<select name="<%=column.Name%>" id="<%=column.Name%>" data-toggle="selectpicker" data-rule="required">
|
||||
<option value="0" @if (Model.<%=column.Name%> == 0) { <text> selected="selected" </text> }>默认</option>
|
||||
<option value="1" @if (Model.<%=column.Name%> == 1) { <text> selected="selected" </text> }>状态1</option>
|
||||
</select>
|
||||
<%} else{%>
|
||||
<label for="<%=column.Name%>" class="control-label x90"><%=column.Description%>:</label>
|
||||
<input type="text" name="<%=column.Name%>" id="<%=column.Name%>" value="@Model.<%=column.Name%>"
|
||||
data-rule="required" size="20">
|
||||
<%} %>
|
||||
</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);
|
||||
|
||||
$('#<%=CascadeId%>').val(ids);
|
||||
}
|
||||
function zTreeOnClick(event, treeId, treeNode) {
|
||||
var zTree = $.fn.zTree.getZTreeObj(treeId);
|
||||
zTree.checkNode(treeNode, !treeNode.checked, true, true);
|
||||
event.preventDefault();
|
||||
}
|
||||
</script>
|
@ -1,138 +1,138 @@
|
||||
<%--
|
||||
Name: Database Table Properties
|
||||
Author: Paul Welter
|
||||
Description: Create a list of properties from a database table
|
||||
--%>
|
||||
<%@ CodeTemplate Language="C#" Encoding="utf-8" TargetLanguage="C#" Debug="False" Description="应用层" %>
|
||||
<%@ Property Name="ModuleName" Type="String" Category="Context" Description="模块名称" %>
|
||||
<%@ Property Name="NeedViewModel" Type="Boolean" Category="Context" Default="False" Description="是否需要ViewModel" %>
|
||||
<%@ Map Name="CSharpAlias" Src="System-CSharpAlias" Description="System to C# Type Map" %>
|
||||
<%@ Assembly Name="SchemaExplorer" %>
|
||||
<%@ Import Namespace="SchemaExplorer" %>
|
||||
<script runat="template">
|
||||
public String GetModelName()
|
||||
{
|
||||
if(NeedViewModel)
|
||||
return ModuleName +"View";
|
||||
else
|
||||
return ModuleName;
|
||||
}
|
||||
</script>
|
||||
|
||||
<%if(NeedViewModel){ %>
|
||||
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 <%=ModuleName%>ManagerApp
|
||||
{
|
||||
private I<%=ModuleName%>Repository _repository;
|
||||
private IOrgRepository _orgRepository;
|
||||
|
||||
public <%=ModuleName%>ManagerApp(I<%=ModuleName%>Repository repository,
|
||||
IOrgRepository orgRepository)
|
||||
{
|
||||
_repository = repository;
|
||||
_orgRepository = orgRepository;
|
||||
}
|
||||
|
||||
public int Get<%=GetModelName()%>CntInOrg(int orgId)
|
||||
{
|
||||
if (orgId == 0)
|
||||
{
|
||||
return _repository.Find(null).Count();
|
||||
}
|
||||
else
|
||||
{
|
||||
return _repository.Get<%=GetModelName()%>CntInOrgs(GetSubOrgIds(orgId));
|
||||
}
|
||||
}
|
||||
|
||||
public List<<%=GetModelName()%>> LoadAll()
|
||||
{
|
||||
return _repository.Find(null).ToList();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 加载一个节点下面的一个或全部<%=GetModelName()%>s
|
||||
/// </summary>
|
||||
public dynamic Load(int orgId, int pageindex, int pagesize)
|
||||
{
|
||||
IEnumerable<<%=ModuleName%>> <%=ModuleName%>s;
|
||||
int total = 0;
|
||||
if (orgId == 0)
|
||||
{
|
||||
<%=ModuleName%>s = _repository.Load<%=ModuleName%>s(pageindex, pagesize);
|
||||
total = _repository.GetCount();
|
||||
}
|
||||
else
|
||||
{
|
||||
<%=ModuleName%>s = _repository.LoadInOrgs(pageindex, pagesize,GetSubOrgIds(orgId));
|
||||
total = _repository.Get<%=ModuleName%>CntInOrgs(orgId);
|
||||
}
|
||||
<%if(NeedViewModel){ %>
|
||||
var <%=ModuleName%>views = new List<<%=ModuleName%>View>();
|
||||
foreach (var <%=ModuleName%> in <%=ModuleName%>s)
|
||||
{
|
||||
<%=ModuleName%>View uv = <%=ModuleName%>;
|
||||
uv.Organizations = string.Join(",", _orgRepository.LoadBy<%=ModuleName%>(<%=ModuleName%>.Id).Select(u => u.Name).ToList());
|
||||
<%=ModuleName%>views.Add(uv);
|
||||
}
|
||||
<%} %>
|
||||
|
||||
return new
|
||||
{
|
||||
total = total,
|
||||
list = <%=GetModelName()%>s,
|
||||
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 <%=GetModelName()%> Find(int id)
|
||||
{
|
||||
var <%=ModuleName.ToLower()%> = _repository.FindSingle(u => u.Id == id);
|
||||
if (<%=ModuleName.ToLower()%> == null) return new <%=GetModelName()%>();
|
||||
|
||||
return <%=ModuleName.ToLower() %>;
|
||||
}
|
||||
|
||||
public void Delete(int id)
|
||||
{
|
||||
_repository.Delete(id);
|
||||
}
|
||||
|
||||
public void AddOrUpdate(<%=GetModelName()%> model)
|
||||
{
|
||||
<%=ModuleName%> <%=ModuleName.ToLower()%> = new <%=ModuleName%>();
|
||||
model.CopyTo(<%=ModuleName.ToLower()%>);
|
||||
|
||||
if (<%=ModuleName.ToLower()%>.Id == 0)
|
||||
{
|
||||
_repository.Add(<%=ModuleName.ToLower()%>);
|
||||
}
|
||||
else
|
||||
{
|
||||
_repository.Update(<%=ModuleName.ToLower()%>);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
<%--
|
||||
Name: Database Table Properties
|
||||
Author: Paul Welter
|
||||
Description: Create a list of properties from a database table
|
||||
--%>
|
||||
<%@ CodeTemplate Language="C#" Encoding="utf-8" TargetLanguage="C#" Debug="False" Description="应用层" %>
|
||||
<%@ Property Name="ModuleName" Type="String" Category="Context" Description="模块名称" %>
|
||||
<%@ Property Name="NeedViewModel" Type="Boolean" Category="Context" Default="False" Description="是否需要ViewModel" %>
|
||||
<%@ Map Name="CSharpAlias" Src="System-CSharpAlias" Description="System to C# Type Map" %>
|
||||
<%@ Assembly Name="SchemaExplorer" %>
|
||||
<%@ Import Namespace="SchemaExplorer" %>
|
||||
<script runat="template">
|
||||
public String GetModelName()
|
||||
{
|
||||
if(NeedViewModel)
|
||||
return ModuleName +"View";
|
||||
else
|
||||
return ModuleName;
|
||||
}
|
||||
</script>
|
||||
|
||||
<%if(NeedViewModel){ %>
|
||||
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 <%=ModuleName%>ManagerApp
|
||||
{
|
||||
private I<%=ModuleName%>Repository _repository;
|
||||
private IOrgRepository _orgRepository;
|
||||
|
||||
public <%=ModuleName%>ManagerApp(I<%=ModuleName%>Repository repository,
|
||||
IOrgRepository orgRepository)
|
||||
{
|
||||
_repository = repository;
|
||||
_orgRepository = orgRepository;
|
||||
}
|
||||
|
||||
public int Get<%=GetModelName()%>CntInOrg(int orgId)
|
||||
{
|
||||
if (orgId == 0)
|
||||
{
|
||||
return _repository.Find(null).Count();
|
||||
}
|
||||
else
|
||||
{
|
||||
return _repository.Get<%=GetModelName()%>CntInOrgs(GetSubOrgIds(orgId));
|
||||
}
|
||||
}
|
||||
|
||||
public List<<%=GetModelName()%>> LoadAll()
|
||||
{
|
||||
return _repository.Find(null).ToList();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 加载一个节点下面的一个或全部<%=GetModelName()%>s
|
||||
/// </summary>
|
||||
public dynamic Load(int orgId, int pageindex, int pagesize)
|
||||
{
|
||||
IEnumerable<<%=ModuleName%>> <%=ModuleName%>s;
|
||||
int total = 0;
|
||||
if (orgId == 0)
|
||||
{
|
||||
<%=ModuleName%>s = _repository.Load<%=ModuleName%>s(pageindex, pagesize);
|
||||
total = _repository.GetCount();
|
||||
}
|
||||
else
|
||||
{
|
||||
<%=ModuleName%>s = _repository.LoadInOrgs(pageindex, pagesize,GetSubOrgIds(orgId));
|
||||
total = _repository.Get<%=ModuleName%>CntInOrgs(orgId);
|
||||
}
|
||||
<%if(NeedViewModel){ %>
|
||||
var <%=ModuleName%>views = new List<<%=ModuleName%>View>();
|
||||
foreach (var <%=ModuleName%> in <%=ModuleName%>s)
|
||||
{
|
||||
<%=ModuleName%>View uv = <%=ModuleName%>;
|
||||
uv.Organizations = string.Join(",", _orgRepository.LoadBy<%=ModuleName%>(<%=ModuleName%>.Id).Select(u => u.Name).ToList());
|
||||
<%=ModuleName%>views.Add(uv);
|
||||
}
|
||||
<%} %>
|
||||
|
||||
return new
|
||||
{
|
||||
total = total,
|
||||
list = <%=GetModelName()%>s,
|
||||
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 <%=GetModelName()%> Find(int id)
|
||||
{
|
||||
var <%=ModuleName.ToLower()%> = _repository.FindSingle(u => u.Id == id);
|
||||
if (<%=ModuleName.ToLower()%> == null) return new <%=GetModelName()%>();
|
||||
|
||||
return <%=ModuleName.ToLower() %>;
|
||||
}
|
||||
|
||||
public void Delete(int id)
|
||||
{
|
||||
_repository.Delete(id);
|
||||
}
|
||||
|
||||
public void AddOrUpdate(<%=GetModelName()%> model)
|
||||
{
|
||||
<%=ModuleName%> <%=ModuleName.ToLower()%> = new <%=ModuleName%>();
|
||||
model.CopyTo(<%=ModuleName.ToLower()%>);
|
||||
|
||||
if (<%=ModuleName.ToLower()%>.Id == 0)
|
||||
{
|
||||
_repository.Add(<%=ModuleName.ToLower()%>);
|
||||
}
|
||||
else
|
||||
{
|
||||
_repository.Update(<%=ModuleName.ToLower()%>);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
@ -1,109 +1,110 @@
|
||||
<%--
|
||||
Name: Database Table Properties
|
||||
Author: Paul Welter
|
||||
Description: Create a list of properties from a database table
|
||||
--%>
|
||||
<%@ CodeTemplate Language="C#" Encoding="utf-8" TargetLanguage="C#" Debug="False" Description="控制器" %>
|
||||
<%@ Property Name="ModuleName" Type="String" Category="Context" Description="模块名称" %>
|
||||
<%@ Property Name="NeedViewModel" Type="Boolean" Category="Context" Default="False" Description="是否需要ViewModel" %>
|
||||
<%@ Map Name="CSharpAlias" Src="System-CSharpAlias" Description="System to C# Type Map" %>
|
||||
<%@ Assembly Name="SchemaExplorer" %>
|
||||
<%@ Import Namespace="SchemaExplorer" %>
|
||||
<script runat="template">
|
||||
public String GetModelName()
|
||||
{
|
||||
if(NeedViewModel)
|
||||
return ModuleName +"View";
|
||||
else
|
||||
return ModuleName;
|
||||
}
|
||||
</script>
|
||||
|
||||
using System;
|
||||
using System.Web.Mvc;
|
||||
using Infrastructure;
|
||||
using OpenAuth.App;
|
||||
<%if(NeedViewModel){ %>
|
||||
using OpenAuth.App.ViewModel;
|
||||
<%} %>
|
||||
|
||||
namespace OpenAuth.Mvc.Controllers
|
||||
{
|
||||
public class <%=ModuleName%>ManagerController : BaseController
|
||||
{
|
||||
private <%=ModuleName%>ManagerApp _app;
|
||||
|
||||
public <%=ModuleName%>ManagerController()
|
||||
{
|
||||
_app = AutofacExt.GetFromFac<<%=ModuleName%>ManagerApp>();
|
||||
}
|
||||
|
||||
//
|
||||
// GET: /UserManager/
|
||||
public ActionResult Index()
|
||||
{
|
||||
return View();
|
||||
}
|
||||
|
||||
public ActionResult Add(int id = 0)
|
||||
{
|
||||
return View(_app.Find(id));
|
||||
}
|
||||
|
||||
//添加或修改<%=ModuleName %>
|
||||
[HttpPost]
|
||||
public string Add(<%=GetModelName()%> model)
|
||||
{
|
||||
try
|
||||
{
|
||||
_app.AddOrUpdate(model);
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
BjuiResponse.statusCode = "300";
|
||||
BjuiResponse.message = ex.Message;
|
||||
}
|
||||
return JsonHelper.Instance.Serialize(BjuiResponse);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 加载节点下面的所有<%=ModuleName %>s
|
||||
/// </summary>
|
||||
public string Load(int parentidId, int pageCurrent = 1, int pageSize = 30)
|
||||
{
|
||||
return JsonHelper.Instance.Serialize(_app.Load(parentidId, pageCurrent, pageSize));
|
||||
}
|
||||
|
||||
public string LoadForTree()
|
||||
{
|
||||
var models = _app.LoadAll();
|
||||
//添加根节点
|
||||
models.Add(new <%=ModuleName %>
|
||||
{
|
||||
Id = 0,
|
||||
ParentId = -1,
|
||||
Name = "根结点",
|
||||
CascadeId = "0"
|
||||
});
|
||||
return JsonHelper.Instance.Serialize(models);
|
||||
}
|
||||
|
||||
public string Delete(int Id)
|
||||
{
|
||||
try
|
||||
{
|
||||
_app.Delete(Id);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
BjuiResponse.statusCode = "300";
|
||||
BjuiResponse.message = e.Message;
|
||||
}
|
||||
|
||||
return JsonHelper.Instance.Serialize(BjuiResponse);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
<%--
|
||||
Name: Database Table Properties
|
||||
Author: Paul Welter
|
||||
Description: Create a list of properties from a database table
|
||||
--%>
|
||||
<%@ CodeTemplate Language="C#" Encoding="utf-8" TargetLanguage="C#" Debug="False" Description="控制器" %>
|
||||
<%@ Property Name="ModuleName" Type="String" Category="Context" Description="模块名称" %>
|
||||
<%@ Property Name="NeedViewModel" Type="Boolean" Category="Context" Default="False" Description="是否需要ViewModel" %>
|
||||
<%@ Map Name="CSharpAlias" Src="System-CSharpAlias" Description="System to C# Type Map" %>
|
||||
<%@ Assembly Name="SchemaExplorer" %>
|
||||
<%@ Import Namespace="SchemaExplorer" %>
|
||||
<script runat="template">
|
||||
public String GetModelName()
|
||||
{
|
||||
if(NeedViewModel)
|
||||
return ModuleName +"View";
|
||||
else
|
||||
return ModuleName;
|
||||
}
|
||||
</script>
|
||||
|
||||
using System;
|
||||
using System.Web.Mvc;
|
||||
using Infrastructure;
|
||||
using OpenAuth.App;
|
||||
<%if(NeedViewModel){ %>
|
||||
using OpenAuth.App.ViewModel;
|
||||
<%} %>
|
||||
using OpenAuth.Domain;
|
||||
|
||||
namespace OpenAuth.Mvc.Controllers
|
||||
{
|
||||
public class <%=ModuleName%>ManagerController : BaseController
|
||||
{
|
||||
private <%=ModuleName%>ManagerApp _app;
|
||||
|
||||
public <%=ModuleName%>ManagerController()
|
||||
{
|
||||
_app = AutofacExt.GetFromFac<<%=ModuleName%>ManagerApp>();
|
||||
}
|
||||
|
||||
//
|
||||
// GET: /UserManager/
|
||||
public ActionResult Index()
|
||||
{
|
||||
return View();
|
||||
}
|
||||
|
||||
public ActionResult Add(int id = 0)
|
||||
{
|
||||
return View(_app.Find(id));
|
||||
}
|
||||
|
||||
//添加或修改<%=ModuleName %>
|
||||
[HttpPost]
|
||||
public string Add(<%=GetModelName()%> model)
|
||||
{
|
||||
try
|
||||
{
|
||||
_app.AddOrUpdate(model);
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
BjuiResponse.statusCode = "300";
|
||||
BjuiResponse.message = ex.Message;
|
||||
}
|
||||
return JsonHelper.Instance.Serialize(BjuiResponse);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 加载节点下面的所有<%=ModuleName %>s
|
||||
/// </summary>
|
||||
public string Load(int parentidId, int pageCurrent = 1, int pageSize = 30)
|
||||
{
|
||||
return JsonHelper.Instance.Serialize(_app.Load(parentidId, pageCurrent, pageSize));
|
||||
}
|
||||
|
||||
public string LoadForTree()
|
||||
{
|
||||
var models = _app.LoadAll();
|
||||
//添加根节点
|
||||
models.Add(new <%=ModuleName %>
|
||||
{
|
||||
Id = 0,
|
||||
ParentId = -1,
|
||||
Name = "根结点",
|
||||
CascadeId = "0"
|
||||
});
|
||||
return JsonHelper.Instance.Serialize(models);
|
||||
}
|
||||
|
||||
public string Delete(int Id)
|
||||
{
|
||||
try
|
||||
{
|
||||
_app.Delete(Id);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
BjuiResponse.statusCode = "300";
|
||||
BjuiResponse.message = e.Message;
|
||||
}
|
||||
|
||||
return JsonHelper.Instance.Serialize(BjuiResponse);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
@ -1,28 +1,28 @@
|
||||
<%--
|
||||
Name: Database Table Properties
|
||||
Author: Paul Welter
|
||||
Description: Create a list of properties from a database table
|
||||
--%>
|
||||
<%@ CodeTemplate Language="C#" Encoding="utf-8" TargetLanguage="C#" Debug="False" Description="创建包含组织机构的接口" %>
|
||||
<%@ Property Name="ModuleName" Type="String" Category="Context" Description="模块名称" %>
|
||||
<%@ Map Name="CSharpAlias" Src="System-CSharpAlias" Description="System to C# Type Map" %>
|
||||
<%@ Assembly Name="SchemaExplorer" %>
|
||||
<%@ Import Namespace="SchemaExplorer" %>
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace OpenAuth.Domain.Interface
|
||||
{
|
||||
public interface I<%=ModuleName%>Repository :IRepository<<%=ModuleName%>>
|
||||
{
|
||||
IEnumerable<<%=ModuleName%>> Load<%=ModuleName%>s(int pageindex, int pagesize);
|
||||
|
||||
IEnumerable<<%=ModuleName%>> LoadInOrgs(params int[] orgId);
|
||||
int Get<%=ModuleName%>CntInOrgs(params int[] orgIds);
|
||||
IEnumerable<<%=ModuleName%>> LoadInOrgs(int pageindex, int pagesize, params int[] orgIds);
|
||||
|
||||
void Delete(int id);
|
||||
|
||||
}
|
||||
<%--
|
||||
Name: Database Table Properties
|
||||
Author: Paul Welter
|
||||
Description: Create a list of properties from a database table
|
||||
--%>
|
||||
<%@ CodeTemplate Language="C#" Encoding="utf-8" TargetLanguage="C#" Debug="False" Description="创建包含组织机构的接口" %>
|
||||
<%@ Property Name="ModuleName" Type="String" Category="Context" Description="模块名称" %>
|
||||
<%@ Map Name="CSharpAlias" Src="System-CSharpAlias" Description="System to C# Type Map" %>
|
||||
<%@ Assembly Name="SchemaExplorer" %>
|
||||
<%@ Import Namespace="SchemaExplorer" %>
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace OpenAuth.Domain.Interface
|
||||
{
|
||||
public interface I<%=ModuleName%>Repository :IRepository<<%=ModuleName%>>
|
||||
{
|
||||
IEnumerable<<%=ModuleName%>> Load<%=ModuleName%>s(int pageindex, int pagesize);
|
||||
|
||||
IEnumerable<<%=ModuleName%>> LoadInOrgs(params int[] orgId);
|
||||
int Get<%=ModuleName%>CntInOrgs(params int[] orgIds);
|
||||
IEnumerable<<%=ModuleName%>> LoadInOrgs(int pageindex, int pagesize, params int[] orgIds);
|
||||
|
||||
void Delete(int id);
|
||||
|
||||
}
|
||||
}
|
@ -1,148 +1,148 @@
|
||||
<%--
|
||||
Name: Database Table Properties
|
||||
Author: Paul Welter
|
||||
Description: Create a list of properties from a database table
|
||||
--%>
|
||||
<%@ CodeTemplate Language="C#" Encoding="utf-8" TargetLanguage="C#" Debug="True" Description="Create a list of properties from database table." %>
|
||||
<%@ Property Name="SourceTable" Type="SchemaExplorer.TableSchema" Category="Context" Description="Table that the object is based on." %>
|
||||
<%@ Property Name="ModuleName" Type="String" Category="Context" Description="模块名称" %>
|
||||
<%@ Map Name="CSharpAlias" Src="System-CSharpAlias" Description="System to C# Type Map" %>
|
||||
<%@ Assembly Name="SchemaExplorer" %>
|
||||
<%@ Import Namespace="SchemaExplorer" %>
|
||||
|
||||
@{
|
||||
string _prefix = "<%=ModuleName%>";
|
||||
var _treeId = _prefix + "Tree";
|
||||
var _gridId = _prefix + "Grid";
|
||||
var _treeDetail = _prefix + "Detail";
|
||||
}
|
||||
|
||||
@{ Html.RenderAction("MenuHeader", "Home");}
|
||||
<div class="bjui-pageContent tableContent">
|
||||
<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 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-hover table-striped table-top"></table>');
|
||||
|
||||
$('#@_gridId').datagrid({
|
||||
showToolbar: false,
|
||||
filterThead: false,
|
||||
columns: [
|
||||
<% foreach (ColumnSchema column in this.SourceTable.Columns) { %>
|
||||
{
|
||||
name: '<%=column.Name%>',
|
||||
label: '<%=column.Description%>',
|
||||
width: 100
|
||||
<%if(column.IsPrimaryKeyMember){ %>
|
||||
, hide: true
|
||||
<%} %>
|
||||
<%else if(CSharpAlias[column.SystemType.FullName] == "System.DateTime") {%>
|
||||
, type: 'date',
|
||||
pattern: 'yyyy-MM-dd HH:mm:ss'
|
||||
<%} %>
|
||||
<%else if(CSharpAlias[column.SystemType.FullName] == "bool") {%>
|
||||
,type: 'select',
|
||||
align: 'center',
|
||||
items: [{ '0': '否' }, { '1': '是' }],
|
||||
<%} %>
|
||||
<%else if(CSharpAlias[column.SystemType.FullName] == "int") {%>
|
||||
,type: 'select',
|
||||
align: 'center',
|
||||
items: [{ '0': '默认' }, { '1': '状态1' }],
|
||||
<%} %>
|
||||
},
|
||||
<% } %>
|
||||
],
|
||||
dataUrl: '<%=ModuleName%>Manager/Load?parentId=' + selectedId,
|
||||
fullGrid: true,
|
||||
showLinenumber: true,
|
||||
showCheckboxcol: true,
|
||||
paging: true,
|
||||
filterMult: false,
|
||||
showTfoot: true,
|
||||
height: '700'
|
||||
});
|
||||
}
|
||||
|
||||
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('<%=ModuleName%>Manager/LoadForTree', function (json) {
|
||||
var zTreeObj = $.fn.zTree.init($('#@_treeId'), setting, json);
|
||||
zTreeObj.expandAll(true);
|
||||
});
|
||||
}
|
||||
|
||||
//删除
|
||||
function del<%=ModuleName%>() {
|
||||
var selected = getSelected('#@_gridId',2);
|
||||
if (selected == null) return;
|
||||
|
||||
$.getJSON('<%=ModuleName%>Manager/Delete?Id=' + selected, function (data) {
|
||||
if (data.statusCode == "200")
|
||||
loadDataGrid();
|
||||
else {
|
||||
$(this).alertmsg('warn', data.message);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
//自定义的编辑按钮
|
||||
function edit<%=ModuleName%>() {
|
||||
var selected = getSelected('#@_gridId',2);
|
||||
if (selected == null) return;
|
||||
|
||||
$(this).dialog({
|
||||
id: 'editDialog',
|
||||
url: '/<%=ModuleName%>Manager/Add?id=' + selected,
|
||||
title: '编辑',
|
||||
onClose:function() {
|
||||
refreshModuleGrid();
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
function refresh<%=ModuleName%>Grid() {
|
||||
$('#@_gridId').datagrid('refresh');
|
||||
// loadDataGrid();
|
||||
}
|
||||
//@@ sourceURL=<%=ModuleName%>ManagerIndex.js
|
||||
</script>
|
||||
<%--
|
||||
Name: Database Table Properties
|
||||
Author: Paul Welter
|
||||
Description: Create a list of properties from a database table
|
||||
--%>
|
||||
<%@ CodeTemplate Language="C#" Encoding="utf-8" TargetLanguage="C#" Debug="True" Description="Create a list of properties from database table." %>
|
||||
<%@ Property Name="SourceTable" Type="SchemaExplorer.TableSchema" Category="Context" Description="Table that the object is based on." %>
|
||||
<%@ Property Name="ModuleName" Type="String" Category="Context" Description="模块名称" %>
|
||||
<%@ Map Name="CSharpAlias" Src="System-CSharpAlias" Description="System to C# Type Map" %>
|
||||
<%@ Assembly Name="SchemaExplorer" %>
|
||||
<%@ Import Namespace="SchemaExplorer" %>
|
||||
|
||||
@{
|
||||
string _prefix = "<%=ModuleName%>";
|
||||
var _treeId = _prefix + "Tree";
|
||||
var _gridId = _prefix + "Grid";
|
||||
var _treeDetail = _prefix + "Detail";
|
||||
}
|
||||
|
||||
@{ Html.RenderAction("MenuHeader", "Home");}
|
||||
<div class="bjui-pageContent tableContent">
|
||||
<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 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-hover table-striped table-top"></table>');
|
||||
|
||||
$('#@_gridId').datagrid({
|
||||
showToolbar: false,
|
||||
filterThead: false,
|
||||
columns: [
|
||||
<% foreach (ColumnSchema column in this.SourceTable.Columns) { %>
|
||||
{
|
||||
name: '<%=column.Name%>',
|
||||
label: '<%=column.Description%>',
|
||||
width: 100
|
||||
<%if(column.IsPrimaryKeyMember){ %>
|
||||
, hide: true
|
||||
<%} %>
|
||||
<%else if(CSharpAlias[column.SystemType.FullName] == "System.DateTime") {%>
|
||||
, type: 'date',
|
||||
pattern: 'yyyy-MM-dd HH:mm:ss'
|
||||
<%} %>
|
||||
<%else if(CSharpAlias[column.SystemType.FullName] == "bool") {%>
|
||||
,type: 'select',
|
||||
align: 'center',
|
||||
items: [{ '0': '否' }, { '1': '是' }],
|
||||
<%} %>
|
||||
<%else if(CSharpAlias[column.SystemType.FullName] == "int") {%>
|
||||
,type: 'select',
|
||||
align: 'center',
|
||||
items: [{ '0': '默认' }, { '1': '状态1' }],
|
||||
<%} %>
|
||||
},
|
||||
<% } %>
|
||||
],
|
||||
dataUrl: '<%=ModuleName%>Manager/Load?parentId=' + selectedId,
|
||||
fullGrid: true,
|
||||
showLinenumber: true,
|
||||
showCheckboxcol: true,
|
||||
paging: true,
|
||||
filterMult: false,
|
||||
showTfoot: true,
|
||||
height: '700'
|
||||
});
|
||||
}
|
||||
|
||||
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('<%=ModuleName%>Manager/LoadForTree', function (json) {
|
||||
var zTreeObj = $.fn.zTree.init($('#@_treeId'), setting, json);
|
||||
zTreeObj.expandAll(true);
|
||||
});
|
||||
}
|
||||
|
||||
//删除
|
||||
function del<%=ModuleName%>() {
|
||||
var selected = getSelected('#@_gridId',2);
|
||||
if (selected == null) return;
|
||||
|
||||
$.getJSON('<%=ModuleName%>Manager/Delete?Id=' + selected, function (data) {
|
||||
if (data.statusCode == "200")
|
||||
loadDataGrid();
|
||||
else {
|
||||
$(this).alertmsg('warn', data.message);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
//自定义的编辑按钮
|
||||
function edit<%=ModuleName%>() {
|
||||
var selected = getSelected('#@_gridId',2);
|
||||
if (selected == null) return;
|
||||
|
||||
$(this).dialog({
|
||||
id: 'editDialog',
|
||||
url: '/<%=ModuleName%>Manager/Add?id=' + selected,
|
||||
title: '编辑',
|
||||
onClose:function() {
|
||||
refreshModuleGrid();
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
function refresh<%=ModuleName%>Grid() {
|
||||
$('#@_gridId').datagrid('refresh');
|
||||
// loadDataGrid();
|
||||
}
|
||||
//@@ sourceURL=<%=ModuleName%>ManagerIndex.js
|
||||
</script>
|
145
CodeSmith/本身带级联/Add.cshtml.cst
Normal file
145
CodeSmith/本身带级联/Add.cshtml.cst
Normal file
@ -0,0 +1,145 @@
|
||||
<%--
|
||||
Name: Database Table Properties
|
||||
Author: Paul Welter
|
||||
Description: Create a list of properties from a database table
|
||||
--%>
|
||||
<%@ CodeTemplate Language="C#" TargetLanguage="C#" Debug="False" Encoding="utf-8" Description="添加模块" %>
|
||||
<%@ Property Name="SourceTable" Type="SchemaExplorer.TableSchema" Category="Context"
|
||||
Description="连接的数据库" %>
|
||||
<%@ Property Name="ModuleName" Type="String" Category="Context" Description="模块名称" %>
|
||||
<%@ Property Name="NeedViewModel" Type="Boolean" Category="Context" Default="False" Description="是否需要ViewModel" %>
|
||||
<%@ Property Name="CascadeId" Type="String" Category="" Default="ParentId" Description="级联字段" %>
|
||||
<%@ Property Name="CascadeName" Type="String" Category="" Default="ParentName" Description="级联显示的文字" %>
|
||||
<%@ Map Name="CSharpAlias" Src="System-CSharpAlias" Description="System to C# Type Map" %>
|
||||
<%@ Assembly Name="SchemaExplorer" %>
|
||||
<%@ Import Namespace="SchemaExplorer" %>
|
||||
<script runat="template">
|
||||
public String GetModelName()
|
||||
{
|
||||
if(NeedViewModel)
|
||||
return ModuleName +"View";
|
||||
else
|
||||
return ModuleName;
|
||||
}
|
||||
</script>
|
||||
<%if(NeedViewModel){ %>
|
||||
@model OpenAuth.App.ViewModel.<%=GetModelName()%>
|
||||
<%} else{ %>
|
||||
@model OpenAuth.Domain.<%=GetModelName()%>
|
||||
<%} %>
|
||||
@{
|
||||
ViewBag.Title = "<%=GetModelName()%>编辑界面";
|
||||
Layout = null;
|
||||
}
|
||||
|
||||
<div class="bjui-pageContent">
|
||||
<form action="/<%=ModuleName%>Manager/Add" class="pageForm" data-toggle="validate">
|
||||
<table class="table table-condensed table-hover">
|
||||
<tbody>
|
||||
<% foreach (ColumnSchema column in this.SourceTable.Columns) {
|
||||
if(column.Name == CascadeName) continue;
|
||||
%>
|
||||
<tr>
|
||||
<td>
|
||||
<%if(column.IsPrimaryKeyMember){ %>
|
||||
@Html.HiddenFor(m =>m.Id)
|
||||
<% } else if(column.Name == CascadeId) {%>
|
||||
<label for="<%=column.Name%>" class="control-label x85"><%=column.Description%>:</label>
|
||||
<input id="<%=column.Name%>" name="<%=column.Name%>" value="" style="display: none"/>
|
||||
<input type="text" name="<%=CascadeName%>" id="<%=CascadeName%>"
|
||||
data-toggle="selectztree" size="20" data-tree="#j_select_tree1" value="@Model.<%=CascadeName%>">
|
||||
<ul id="j_select_tree1" class="ztree hide" data-toggle="ztree"></ul>
|
||||
|
||||
<% } else if(CSharpAlias[column.SystemType.FullName] == "bool") {%>
|
||||
<label for="<%=column.Name%>" class="control-label x85"><%=column.Description%>:</label>
|
||||
|
||||
<select name="<%=column.Name%>" id="<%=column.Name%>" data-toggle="selectpicker" data-rule="required">
|
||||
<option value="0" @if (Model.<%=column.Name%>) { <text> selected="selected" </text> }>否</option>
|
||||
<option value="1" @if (!Model.<%=column.Name%>) { <text> selected="selected" </text> }>是</option>
|
||||
</select>
|
||||
<%} else if(CSharpAlias[column.SystemType.FullName] == "int") {%>
|
||||
<label for="<%=column.Name%>" class="control-label x85"><%=column.Description%>:</label>
|
||||
<select name="<%=column.Name%>" id="<%=column.Name%>" data-toggle="selectpicker" data-rule="required">
|
||||
<option value="0" @if (Model.<%=column.Name%> == 0) { <text> selected="selected" </text> }>默认</option>
|
||||
<option value="1" @if (Model.<%=column.Name%> == 1) { <text> selected="selected" </text> }>状态1</option>
|
||||
</select>
|
||||
<%} else{%>
|
||||
<label for="<%=column.Name%>" class="control-label x90"><%=column.Description%>:</label>
|
||||
<input type="text" name="<%=column.Name%>" id="<%=column.Name%>" value="@Model.<%=column.Name%>"
|
||||
data-rule="required" size="20">
|
||||
<%} %>
|
||||
</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);
|
||||
|
||||
$('#<%=CascadeId%>').val(ids);
|
||||
}
|
||||
function zTreeOnClick(event, treeId, treeNode) {
|
||||
var zTree = $.fn.zTree.getZTreeObj(treeId);
|
||||
zTree.checkNode(treeNode, !treeNode.checked, true, true);
|
||||
event.preventDefault();
|
||||
}
|
||||
</script>
|
138
CodeSmith/本身带级联/Application.cst
Normal file
138
CodeSmith/本身带级联/Application.cst
Normal file
@ -0,0 +1,138 @@
|
||||
<%--
|
||||
Name: Database Table Properties
|
||||
Author: Paul Welter
|
||||
Description: Create a list of properties from a database table
|
||||
--%>
|
||||
<%@ CodeTemplate Language="C#" Encoding="utf-8" TargetLanguage="C#" Debug="False" Description="应用层" %>
|
||||
<%@ Property Name="ModuleName" Type="String" Category="Context" Description="模块名称" %>
|
||||
<%@ Property Name="NeedViewModel" Type="Boolean" Category="Context" Default="False" Description="是否需要ViewModel" %>
|
||||
<%@ Map Name="CSharpAlias" Src="System-CSharpAlias" Description="System to C# Type Map" %>
|
||||
<%@ Assembly Name="SchemaExplorer" %>
|
||||
<%@ Import Namespace="SchemaExplorer" %>
|
||||
<script runat="template">
|
||||
public String GetModelName()
|
||||
{
|
||||
if(NeedViewModel)
|
||||
return ModuleName +"View";
|
||||
else
|
||||
return ModuleName;
|
||||
}
|
||||
</script>
|
||||
|
||||
<%if(NeedViewModel){ %>
|
||||
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 <%=ModuleName%>ManagerApp
|
||||
{
|
||||
private I<%=ModuleName%>Repository _repository;
|
||||
private IOrgRepository _orgRepository;
|
||||
|
||||
public <%=ModuleName%>ManagerApp(I<%=ModuleName%>Repository repository,
|
||||
IOrgRepository orgRepository)
|
||||
{
|
||||
_repository = repository;
|
||||
_orgRepository = orgRepository;
|
||||
}
|
||||
|
||||
public int Get<%=GetModelName()%>CntInOrg(int orgId)
|
||||
{
|
||||
if (orgId == 0)
|
||||
{
|
||||
return _repository.Find(null).Count();
|
||||
}
|
||||
else
|
||||
{
|
||||
return _repository.Get<%=GetModelName()%>CntInOrgs(GetSubOrgIds(orgId));
|
||||
}
|
||||
}
|
||||
|
||||
public List<<%=GetModelName()%>> LoadAll()
|
||||
{
|
||||
return _repository.Find(null).ToList();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 加载一个节点下面的一个或全部<%=GetModelName()%>s
|
||||
/// </summary>
|
||||
public dynamic Load(int orgId, int pageindex, int pagesize)
|
||||
{
|
||||
IEnumerable<<%=ModuleName%>> <%=ModuleName%>s;
|
||||
int total = 0;
|
||||
if (orgId == 0)
|
||||
{
|
||||
<%=ModuleName%>s = _repository.Load<%=ModuleName%>s(pageindex, pagesize);
|
||||
total = _repository.GetCount();
|
||||
}
|
||||
else
|
||||
{
|
||||
<%=ModuleName%>s = _repository.LoadInOrgs(pageindex, pagesize,GetSubOrgIds(orgId));
|
||||
total = _repository.Get<%=ModuleName%>CntInOrgs(orgId);
|
||||
}
|
||||
<%if(NeedViewModel){ %>
|
||||
var <%=ModuleName%>views = new List<<%=ModuleName%>View>();
|
||||
foreach (var <%=ModuleName%> in <%=ModuleName%>s)
|
||||
{
|
||||
<%=ModuleName%>View uv = <%=ModuleName%>;
|
||||
uv.Organizations = string.Join(",", _orgRepository.LoadBy<%=ModuleName%>(<%=ModuleName%>.Id).Select(u => u.Name).ToList());
|
||||
<%=ModuleName%>views.Add(uv);
|
||||
}
|
||||
<%} %>
|
||||
|
||||
return new
|
||||
{
|
||||
total = total,
|
||||
list = <%=GetModelName()%>s,
|
||||
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 <%=GetModelName()%> Find(int id)
|
||||
{
|
||||
var <%=ModuleName.ToLower()%> = _repository.FindSingle(u => u.Id == id);
|
||||
if (<%=ModuleName.ToLower()%> == null) return new <%=GetModelName()%>();
|
||||
|
||||
return <%=ModuleName.ToLower() %>;
|
||||
}
|
||||
|
||||
public void Delete(int id)
|
||||
{
|
||||
_repository.Delete(id);
|
||||
}
|
||||
|
||||
public void AddOrUpdate(<%=GetModelName()%> model)
|
||||
{
|
||||
<%=ModuleName%> <%=ModuleName.ToLower()%> = new <%=ModuleName%>();
|
||||
model.CopyTo(<%=ModuleName.ToLower()%>);
|
||||
|
||||
if (<%=ModuleName.ToLower()%>.Id == 0)
|
||||
{
|
||||
_repository.Add(<%=ModuleName.ToLower()%>);
|
||||
}
|
||||
else
|
||||
{
|
||||
_repository.Update(<%=ModuleName.ToLower()%>);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
110
CodeSmith/本身带级联/Controller.cst
Normal file
110
CodeSmith/本身带级联/Controller.cst
Normal file
@ -0,0 +1,110 @@
|
||||
<%--
|
||||
Name: Database Table Properties
|
||||
Author: Paul Welter
|
||||
Description: Create a list of properties from a database table
|
||||
--%>
|
||||
<%@ CodeTemplate Language="C#" Encoding="utf-8" TargetLanguage="C#" Debug="False" Description="控制器" %>
|
||||
<%@ Property Name="ModuleName" Type="String" Category="Context" Description="模块名称" %>
|
||||
<%@ Property Name="NeedViewModel" Type="Boolean" Category="Context" Default="False" Description="是否需要ViewModel" %>
|
||||
<%@ Map Name="CSharpAlias" Src="System-CSharpAlias" Description="System to C# Type Map" %>
|
||||
<%@ Assembly Name="SchemaExplorer" %>
|
||||
<%@ Import Namespace="SchemaExplorer" %>
|
||||
<script runat="template">
|
||||
public String GetModelName()
|
||||
{
|
||||
if(NeedViewModel)
|
||||
return ModuleName +"View";
|
||||
else
|
||||
return ModuleName;
|
||||
}
|
||||
</script>
|
||||
|
||||
using System;
|
||||
using System.Web.Mvc;
|
||||
using Infrastructure;
|
||||
using OpenAuth.App;
|
||||
<%if(NeedViewModel){ %>
|
||||
using OpenAuth.App.ViewModel;
|
||||
<%} %>
|
||||
using OpenAuth.Domain;
|
||||
|
||||
namespace OpenAuth.Mvc.Controllers
|
||||
{
|
||||
public class <%=ModuleName%>ManagerController : BaseController
|
||||
{
|
||||
private <%=ModuleName%>ManagerApp _app;
|
||||
|
||||
public <%=ModuleName%>ManagerController()
|
||||
{
|
||||
_app = AutofacExt.GetFromFac<<%=ModuleName%>ManagerApp>();
|
||||
}
|
||||
|
||||
//
|
||||
// GET: /UserManager/
|
||||
public ActionResult Index()
|
||||
{
|
||||
return View();
|
||||
}
|
||||
|
||||
public ActionResult Add(int id = 0)
|
||||
{
|
||||
return View(_app.Find(id));
|
||||
}
|
||||
|
||||
//添加或修改<%=ModuleName %>
|
||||
[HttpPost]
|
||||
public string Add(<%=GetModelName()%> model)
|
||||
{
|
||||
try
|
||||
{
|
||||
_app.AddOrUpdate(model);
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
BjuiResponse.statusCode = "300";
|
||||
BjuiResponse.message = ex.Message;
|
||||
}
|
||||
return JsonHelper.Instance.Serialize(BjuiResponse);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 加载节点下面的所有<%=ModuleName %>s
|
||||
/// </summary>
|
||||
public string Load(int parentidId, int pageCurrent = 1, int pageSize = 30)
|
||||
{
|
||||
return JsonHelper.Instance.Serialize(_app.Load(parentidId, pageCurrent, pageSize));
|
||||
}
|
||||
|
||||
public string LoadForTree()
|
||||
{
|
||||
var models = _app.LoadAll();
|
||||
//添加根节点
|
||||
models.Add(new <%=ModuleName %>
|
||||
{
|
||||
Id = 0,
|
||||
ParentId = -1,
|
||||
Name = "根结点",
|
||||
CascadeId = "0"
|
||||
});
|
||||
return JsonHelper.Instance.Serialize(models);
|
||||
}
|
||||
|
||||
public string Delete(int Id)
|
||||
{
|
||||
try
|
||||
{
|
||||
_app.Delete(Id);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
BjuiResponse.statusCode = "300";
|
||||
BjuiResponse.message = e.Message;
|
||||
}
|
||||
|
||||
return JsonHelper.Instance.Serialize(BjuiResponse);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
28
CodeSmith/本身带级联/IRepository.cst
Normal file
28
CodeSmith/本身带级联/IRepository.cst
Normal file
@ -0,0 +1,28 @@
|
||||
<%--
|
||||
Name: Database Table Properties
|
||||
Author: Paul Welter
|
||||
Description: Create a list of properties from a database table
|
||||
--%>
|
||||
<%@ CodeTemplate Language="C#" Encoding="utf-8" TargetLanguage="C#" Debug="False" Description="创建包含组织机构的接口" %>
|
||||
<%@ Property Name="ModuleName" Type="String" Category="Context" Description="模块名称" %>
|
||||
<%@ Map Name="CSharpAlias" Src="System-CSharpAlias" Description="System to C# Type Map" %>
|
||||
<%@ Assembly Name="SchemaExplorer" %>
|
||||
<%@ Import Namespace="SchemaExplorer" %>
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace OpenAuth.Domain.Interface
|
||||
{
|
||||
public interface I<%=ModuleName%>Repository :IRepository<<%=ModuleName%>>
|
||||
{
|
||||
IEnumerable<<%=ModuleName%>> Load<%=ModuleName%>s(int pageindex, int pagesize);
|
||||
|
||||
IEnumerable<<%=ModuleName%>> LoadInOrgs(params int[] orgId);
|
||||
int Get<%=ModuleName%>CntInOrgs(params int[] orgIds);
|
||||
IEnumerable<<%=ModuleName%>> LoadInOrgs(int pageindex, int pagesize, params int[] orgIds);
|
||||
|
||||
void Delete(int id);
|
||||
|
||||
}
|
||||
}
|
148
CodeSmith/本身带级联/Index.cshtml.cst
Normal file
148
CodeSmith/本身带级联/Index.cshtml.cst
Normal file
@ -0,0 +1,148 @@
|
||||
<%--
|
||||
Name: Database Table Properties
|
||||
Author: Paul Welter
|
||||
Description: Create a list of properties from a database table
|
||||
--%>
|
||||
<%@ CodeTemplate Language="C#" Encoding="utf-8" TargetLanguage="C#" Debug="True" Description="Create a list of properties from database table." %>
|
||||
<%@ Property Name="SourceTable" Type="SchemaExplorer.TableSchema" Category="Context" Description="Table that the object is based on." %>
|
||||
<%@ Property Name="ModuleName" Type="String" Category="Context" Description="模块名称" %>
|
||||
<%@ Map Name="CSharpAlias" Src="System-CSharpAlias" Description="System to C# Type Map" %>
|
||||
<%@ Assembly Name="SchemaExplorer" %>
|
||||
<%@ Import Namespace="SchemaExplorer" %>
|
||||
|
||||
@{
|
||||
string _prefix = "<%=ModuleName%>";
|
||||
var _treeId = _prefix + "Tree";
|
||||
var _gridId = _prefix + "Grid";
|
||||
var _treeDetail = _prefix + "Detail";
|
||||
}
|
||||
|
||||
@{ Html.RenderAction("MenuHeader", "Home");}
|
||||
<div class="bjui-pageContent tableContent">
|
||||
<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 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-hover table-striped table-top"></table>');
|
||||
|
||||
$('#@_gridId').datagrid({
|
||||
showToolbar: false,
|
||||
filterThead: false,
|
||||
columns: [
|
||||
<% foreach (ColumnSchema column in this.SourceTable.Columns) { %>
|
||||
{
|
||||
name: '<%=column.Name%>',
|
||||
label: '<%=column.Description%>',
|
||||
width: 100
|
||||
<%if(column.IsPrimaryKeyMember){ %>
|
||||
, hide: true
|
||||
<%} %>
|
||||
<%else if(CSharpAlias[column.SystemType.FullName] == "System.DateTime") {%>
|
||||
, type: 'date',
|
||||
pattern: 'yyyy-MM-dd HH:mm:ss'
|
||||
<%} %>
|
||||
<%else if(CSharpAlias[column.SystemType.FullName] == "bool") {%>
|
||||
,type: 'select',
|
||||
align: 'center',
|
||||
items: [{ '0': '否' }, { '1': '是' }],
|
||||
<%} %>
|
||||
<%else if(CSharpAlias[column.SystemType.FullName] == "int") {%>
|
||||
,type: 'select',
|
||||
align: 'center',
|
||||
items: [{ '0': '默认' }, { '1': '状态1' }],
|
||||
<%} %>
|
||||
},
|
||||
<% } %>
|
||||
],
|
||||
dataUrl: '<%=ModuleName%>Manager/Load?parentId=' + selectedId,
|
||||
fullGrid: true,
|
||||
showLinenumber: true,
|
||||
showCheckboxcol: true,
|
||||
paging: true,
|
||||
filterMult: false,
|
||||
showTfoot: true,
|
||||
height: '700'
|
||||
});
|
||||
}
|
||||
|
||||
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('<%=ModuleName%>Manager/LoadForTree', function (json) {
|
||||
var zTreeObj = $.fn.zTree.init($('#@_treeId'), setting, json);
|
||||
zTreeObj.expandAll(true);
|
||||
});
|
||||
}
|
||||
|
||||
//删除
|
||||
function del<%=ModuleName%>() {
|
||||
var selected = getSelected('#@_gridId',2);
|
||||
if (selected == null) return;
|
||||
|
||||
$.getJSON('<%=ModuleName%>Manager/Delete?Id=' + selected, function (data) {
|
||||
if (data.statusCode == "200")
|
||||
loadDataGrid();
|
||||
else {
|
||||
$(this).alertmsg('warn', data.message);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
//自定义的编辑按钮
|
||||
function edit<%=ModuleName%>() {
|
||||
var selected = getSelected('#@_gridId',2);
|
||||
if (selected == null) return;
|
||||
|
||||
$(this).dialog({
|
||||
id: 'editDialog',
|
||||
url: '/<%=ModuleName%>Manager/Add?id=' + selected,
|
||||
title: '编辑',
|
||||
onClose:function() {
|
||||
refreshModuleGrid();
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
function refresh<%=ModuleName%>Grid() {
|
||||
$('#@_gridId').datagrid('refresh');
|
||||
// loadDataGrid();
|
||||
}
|
||||
//@@ sourceURL=<%=ModuleName%>ManagerIndex.js
|
||||
</script>
|
@ -47,6 +47,7 @@
|
||||
<Compile Include="LoginApp.cs" />
|
||||
<Compile Include="ModuleElementManagerApp.cs" />
|
||||
<Compile Include="ModuleManagerApp.cs" />
|
||||
<Compile Include="ResourceManagerApp.cs" />
|
||||
<Compile Include="RoleManagerApp.cs" />
|
||||
<Compile Include="UserManagerApp.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
|
107
OpenAuth.App/ResourceManagerApp.cs
Normal file
107
OpenAuth.App/ResourceManagerApp.cs
Normal file
@ -0,0 +1,107 @@
|
||||
|
||||
using OpenAuth.Domain;
|
||||
using OpenAuth.Domain.Interface;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Infrastructure;
|
||||
|
||||
namespace OpenAuth.App
|
||||
{
|
||||
public class ResourceManagerApp
|
||||
{
|
||||
private IResourceRepository _repository;
|
||||
private readonly ICategoryRepository _categoryRepository;
|
||||
|
||||
public ResourceManagerApp(IResourceRepository repository,
|
||||
ICategoryRepository categoryRepository)
|
||||
{
|
||||
_repository = repository;
|
||||
_categoryRepository = categoryRepository;
|
||||
}
|
||||
|
||||
public int GetResourceCntInOrg(int orgId)
|
||||
{
|
||||
if (orgId == 0)
|
||||
{
|
||||
return _repository.Find(null).Count();
|
||||
}
|
||||
else
|
||||
{
|
||||
return _repository.GetResourceCntInOrgs(GetSubOrgIds(orgId));
|
||||
}
|
||||
}
|
||||
|
||||
public List<Resource> LoadAll()
|
||||
{
|
||||
return _repository.Find(null).ToList();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 加载一个节点下面的一个或全部Resources
|
||||
/// </summary>
|
||||
public dynamic Load(int categoryId, int pageindex, int pagesize)
|
||||
{
|
||||
IEnumerable<Resource> Resources;
|
||||
int total = 0;
|
||||
if (categoryId == 0)
|
||||
{
|
||||
Resources = _repository.LoadResources(pageindex, pagesize);
|
||||
total = _repository.GetCount();
|
||||
}
|
||||
else
|
||||
{
|
||||
Resources = _repository.LoadInOrgs(pageindex, pagesize,GetSubOrgIds(categoryId));
|
||||
total = _repository.GetResourceCntInOrgs(categoryId);
|
||||
}
|
||||
|
||||
return new
|
||||
{
|
||||
total = total,
|
||||
list = Resources,
|
||||
pageCurrent = pageindex
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取当前节点的所有下级节点
|
||||
/// </summary>
|
||||
private int[] GetSubOrgIds(int orgId)
|
||||
{
|
||||
var org = _categoryRepository.FindSingle(u => u.Id == orgId);
|
||||
var orgs = _categoryRepository.Find(u => u.CascadeId.Contains(org.CascadeId)).Select(u => u.Id).ToArray();
|
||||
return orgs;
|
||||
}
|
||||
|
||||
public Resource Find(int id)
|
||||
{
|
||||
var resource = _repository.FindSingle(u => u.Id == id);
|
||||
if (resource == null) return new Resource();
|
||||
|
||||
return resource;
|
||||
}
|
||||
|
||||
public void Delete(int id)
|
||||
{
|
||||
_repository.Delete(id);
|
||||
}
|
||||
|
||||
public void AddOrUpdate(Resource model)
|
||||
{
|
||||
Resource resource = new Resource();
|
||||
model.CopyTo(resource);
|
||||
|
||||
if (resource.Id == 0)
|
||||
{
|
||||
_repository.Add(resource);
|
||||
}
|
||||
else
|
||||
{
|
||||
_repository.Update(resource);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
17
OpenAuth.Domain/Interface/IResourceRepository.cs
Normal file
17
OpenAuth.Domain/Interface/IResourceRepository.cs
Normal file
@ -0,0 +1,17 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace OpenAuth.Domain.Interface
|
||||
{
|
||||
public interface IResourceRepository :IRepository<Resource>
|
||||
{
|
||||
IEnumerable<Resource> LoadResources(int pageindex, int pagesize);
|
||||
|
||||
IEnumerable<Resource> LoadInOrgs(params int[] orgId);
|
||||
int GetResourceCntInOrgs(params int[] orgIds);
|
||||
IEnumerable<Resource> LoadInOrgs(int pageindex, int pagesize, params int[] orgIds);
|
||||
|
||||
void Delete(int id);
|
||||
|
||||
}
|
||||
}
|
@ -50,6 +50,7 @@
|
||||
<Compile Include="Interface\IModuleRepository.cs" />
|
||||
<Compile Include="Interface\IOrgRepository.cs" />
|
||||
<Compile Include="Interface\IRepository.cs" />
|
||||
<Compile Include="Interface\IResourceRepository.cs" />
|
||||
<Compile Include="Interface\IRoleRepository.cs" />
|
||||
<Compile Include="Interface\IRelevanceRepository.cs" />
|
||||
<Compile Include="Interface\IUserRepository.cs" />
|
||||
|
87
OpenAuth.Mvc/Controllers/ResourceManagerController.cs
Normal file
87
OpenAuth.Mvc/Controllers/ResourceManagerController.cs
Normal file
@ -0,0 +1,87 @@
|
||||
|
||||
using System;
|
||||
using System.Web.Mvc;
|
||||
using Infrastructure;
|
||||
using OpenAuth.App;
|
||||
using OpenAuth.Domain;
|
||||
|
||||
namespace OpenAuth.Mvc.Controllers
|
||||
{
|
||||
public class ResourceManagerController : BaseController
|
||||
{
|
||||
private ResourceManagerApp _app;
|
||||
|
||||
public ResourceManagerController()
|
||||
{
|
||||
_app = AutofacExt.GetFromFac<ResourceManagerApp>();
|
||||
}
|
||||
|
||||
//
|
||||
// GET: /UserManager/
|
||||
public ActionResult Index()
|
||||
{
|
||||
return View();
|
||||
}
|
||||
|
||||
public ActionResult Add(int id = 0)
|
||||
{
|
||||
return View(_app.Find(id));
|
||||
}
|
||||
|
||||
//添加或修改Resource
|
||||
[HttpPost]
|
||||
public string Add(Resource model)
|
||||
{
|
||||
try
|
||||
{
|
||||
_app.AddOrUpdate(model);
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
BjuiResponse.statusCode = "300";
|
||||
BjuiResponse.message = ex.Message;
|
||||
}
|
||||
return JsonHelper.Instance.Serialize(BjuiResponse);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 加载某分类的所有Resources
|
||||
/// </summary>
|
||||
public string Load(int categoryId, int pageCurrent = 1, int pageSize = 30)
|
||||
{
|
||||
return JsonHelper.Instance.Serialize(_app.Load(categoryId, pageCurrent, pageSize));
|
||||
}
|
||||
|
||||
public string LoadForTree()
|
||||
{
|
||||
var models = _app.LoadAll();
|
||||
//添加根节点
|
||||
models.Add(new Resource
|
||||
{
|
||||
Id = 0,
|
||||
ParentId = -1,
|
||||
Name = "根结点",
|
||||
CascadeId = "0"
|
||||
});
|
||||
return JsonHelper.Instance.Serialize(models);
|
||||
}
|
||||
|
||||
public string Delete(int Id)
|
||||
{
|
||||
try
|
||||
{
|
||||
_app.Delete(Id);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
BjuiResponse.statusCode = "300";
|
||||
BjuiResponse.message = e.Message;
|
||||
}
|
||||
|
||||
return JsonHelper.Instance.Serialize(BjuiResponse);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
@ -133,6 +133,7 @@
|
||||
<Compile Include="Controllers\ModuleElementManagerController.cs" />
|
||||
<Compile Include="Controllers\ModuleManagerController.cs" />
|
||||
<Compile Include="Controllers\OrgManagerController.cs" />
|
||||
<Compile Include="Controllers\ResourceManagerController.cs" />
|
||||
<Compile Include="Controllers\RoleManagerController.cs" />
|
||||
<Compile Include="Controllers\UserManagerController.cs" />
|
||||
<Compile Include="Global.asax.cs">
|
||||
@ -571,6 +572,8 @@
|
||||
<Content Include="Views\_ViewStart.cshtml" />
|
||||
<Content Include="Views\Shared\_Layout.cshtml" />
|
||||
<Content Include="Views\Home\Index.cshtml" />
|
||||
<Content Include="Views\ResourceManager\Add.cshtml" />
|
||||
<Content Include="Views\ResourceManager\Index.cshtml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Folder Include="App_Data\" />
|
||||
|
@ -54,9 +54,6 @@
|
||||
name: 'ParentId',
|
||||
label: '父节点流水号',
|
||||
width: 100
|
||||
,type: 'select',
|
||||
align: 'center',
|
||||
items: [{ '0': '默认' }, { '1': '状态1' }],
|
||||
},
|
||||
{
|
||||
name: 'Status',
|
||||
|
152
OpenAuth.Mvc/Views/ResourceManager/Add.cshtml
Normal file
152
OpenAuth.Mvc/Views/ResourceManager/Add.cshtml
Normal file
@ -0,0 +1,152 @@
|
||||
@model OpenAuth.Domain.Resource
|
||||
@{
|
||||
ViewBag.Title = "Resource编辑界面";
|
||||
Layout = null;
|
||||
}
|
||||
|
||||
<div class="bjui-pageContent">
|
||||
<form action="/ResourceManager/Add" class="pageForm" data-toggle="validate">
|
||||
<table class="table table-condensed table-hover">
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>
|
||||
@Html.HiddenFor(m =>m.Id)
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<label for="CascadeId" class="control-label x90">节点语义ID:</label>
|
||||
<input type="text" name="CascadeId" id="CascadeId" value="@Model.CascadeId"
|
||||
data-rule="required" size="20">
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<label for="Key" class="control-label x90">:</label>
|
||||
<input type="text" name="Key" id="Key" value="@Model.Key"
|
||||
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"
|
||||
data-rule="required" size="20">
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<label for="ParentId" class="control-label x85">父节点流水号:</label>
|
||||
<input id="ParentId" name="ParentId" value="" style="display: none"/>
|
||||
<input type="text" name="ParentName" id="ParentName"
|
||||
data-toggle="selectztree" size="20" data-tree="#j_select_tree1" value="@Model.ParentName">
|
||||
<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" @if (Model.Status == 0) { <text> selected="selected" </text> }>默认</option>
|
||||
<option value="1" @if (Model.Status == 1) { <text> selected="selected" </text> }>状态1</option>
|
||||
</select>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<label for="SortNo" class="control-label x85">排序号:</label>
|
||||
<select name="SortNo" id="SortNo" data-toggle="selectpicker" data-rule="required">
|
||||
<option value="0" @if (Model.SortNo == 0) { <text> selected="selected" </text> }>默认</option>
|
||||
<option value="1" @if (Model.SortNo == 1) { <text> selected="selected" </text> }>状态1</option>
|
||||
</select>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<label for="CategoryId" class="control-label x85">资源分类标识:</label>
|
||||
<select name="CategoryId" id="CategoryId" data-toggle="selectpicker" data-rule="required">
|
||||
<option value="0" @if (Model.CategoryId == 0) { <text> selected="selected" </text> }>默认</option>
|
||||
<option value="1" @if (Model.CategoryId == 1) { <text> selected="selected" </text> }>状态1</option>
|
||||
</select>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<label for="Description" class="control-label x90">描述:</label>
|
||||
<input type="text" name="Description" id="Description" value="@Model.Description"
|
||||
data-rule="required" size="20">
|
||||
</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);
|
||||
|
||||
$('#ParentId').val(ids);
|
||||
}
|
||||
function zTreeOnClick(event, treeId, treeNode) {
|
||||
var zTree = $.fn.zTree.getZTreeObj(treeId);
|
||||
zTree.checkNode(treeNode, !treeNode.checked, true, true);
|
||||
event.preventDefault();
|
||||
}
|
||||
</script>
|
170
OpenAuth.Mvc/Views/ResourceManager/Index.cshtml
Normal file
170
OpenAuth.Mvc/Views/ResourceManager/Index.cshtml
Normal file
@ -0,0 +1,170 @@
|
||||
@{
|
||||
string _prefix = "Resource";
|
||||
var _treeId = _prefix + "Tree";
|
||||
var _gridId = _prefix + "Grid";
|
||||
var _treeDetail = _prefix + "Detail";
|
||||
}
|
||||
|
||||
@{ Html.RenderAction("MenuHeader", "Home");}
|
||||
<div class="bjui-pageContent tableContent">
|
||||
<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 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-hover table-striped table-top"></table>');
|
||||
|
||||
$('#@_gridId').datagrid({
|
||||
showToolbar: false,
|
||||
filterThead: false,
|
||||
columns: [
|
||||
{
|
||||
name: 'Id',
|
||||
label: '资源表ID',
|
||||
width: 100
|
||||
, hide: true
|
||||
},
|
||||
{
|
||||
name: 'CascadeId',
|
||||
label: '节点语义ID',
|
||||
width: 100
|
||||
},
|
||||
{
|
||||
name: 'Key',
|
||||
label: '',
|
||||
width: 100
|
||||
},
|
||||
{
|
||||
name: 'Name',
|
||||
label: '名称',
|
||||
width: 100
|
||||
},
|
||||
{
|
||||
name: 'ParentId',
|
||||
label: '父节点流水号',
|
||||
width: 100
|
||||
,type: 'select',
|
||||
align: 'center',
|
||||
items: [{ '0': '默认' }, { '1': '状态1' }],
|
||||
},
|
||||
{
|
||||
name: 'Status',
|
||||
label: '当前状态',
|
||||
width: 100
|
||||
,type: 'select',
|
||||
align: 'center',
|
||||
items: [{ '0': '默认' }, { '1': '状态1' }],
|
||||
},
|
||||
{
|
||||
name: 'SortNo',
|
||||
label: '排序号',
|
||||
width: 100
|
||||
,type: 'select',
|
||||
align: 'center',
|
||||
items: [{ '0': '默认' }, { '1': '状态1' }],
|
||||
},
|
||||
{
|
||||
name: 'CategoryId',
|
||||
label: '资源分类标识',
|
||||
width: 100
|
||||
,type: 'select',
|
||||
align: 'center',
|
||||
items: [{ '0': '默认' }, { '1': '状态1' }],
|
||||
},
|
||||
{
|
||||
name: 'Description',
|
||||
label: '描述',
|
||||
width: 100
|
||||
},
|
||||
],
|
||||
dataUrl: 'ResourceManager/Load?categoryId=' + selectedId,
|
||||
fullGrid: true,
|
||||
showLinenumber: true,
|
||||
showCheckboxcol: true,
|
||||
paging: true,
|
||||
filterMult: false,
|
||||
showTfoot: true,
|
||||
height: '700'
|
||||
});
|
||||
}
|
||||
|
||||
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('CategoryManager/LoadForTree', function (json) {
|
||||
var zTreeObj = $.fn.zTree.init($('#@_treeId'), setting, json);
|
||||
zTreeObj.expandAll(true);
|
||||
});
|
||||
}
|
||||
|
||||
//删除
|
||||
function delResource() {
|
||||
var selected = getSelected('#@_gridId',2);
|
||||
if (selected == null) return;
|
||||
|
||||
$.getJSON('ResourceManager/Delete?Id=' + selected, function (data) {
|
||||
if (data.statusCode == "200")
|
||||
loadDataGrid();
|
||||
else {
|
||||
$(this).alertmsg('warn', data.message);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
//自定义的编辑按钮
|
||||
function editResource() {
|
||||
var selected = getSelected('#@_gridId',2);
|
||||
if (selected == null) return;
|
||||
|
||||
$(this).dialog({
|
||||
id: 'editDialog',
|
||||
url: '/ResourceManager/Add?id=' + selected,
|
||||
title: '编辑',
|
||||
onClose:function() {
|
||||
refreshModuleGrid();
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
function refreshResourceGrid() {
|
||||
$('#@_gridId').datagrid('refresh');
|
||||
// loadDataGrid();
|
||||
}
|
||||
//@@ sourceURL=ResourceManagerIndex.js
|
||||
</script>
|
@ -71,6 +71,7 @@
|
||||
<Compile Include="OrgRepository.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="ModuleRepository.cs" />
|
||||
<Compile Include="ResourceRepository.cs" />
|
||||
<Compile Include="RoleRepository.cs" />
|
||||
<Compile Include="CategoryRepository.cs" />
|
||||
<Compile Include="UserRepository.cs" />
|
||||
|
41
OpenAuth.Repository/ResourceRepository.cs
Normal file
41
OpenAuth.Repository/ResourceRepository.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.Id).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.Id).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;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
@ -1,41 +1,37 @@
|
||||
using System;
|
||||
using OpenAuth.Domain;
|
||||
using OpenAuth.Domain.Interface;
|
||||
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 class ResourceRepository : BaseRepository<Resource>, IResourceRepository
|
||||
{
|
||||
public IEnumerable<Role> LoadRoles(int pageindex, int pagesize)
|
||||
{
|
||||
return Context.Roles.OrderBy(u => u.Id).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)
|
||||
public IEnumerable<Resource> LoadInOrgs(int pageindex, int pagesize, params int[] orgIds)
|
||||
{
|
||||
return LoadInOrgs(orgIds).OrderBy(u => u.Id).Skip((pageindex - 1) * pagesize).Take(pagesize);
|
||||
}
|
||||
|
||||
public void Delete(int id)
|
||||
{
|
||||
Delete(u =>u.Id == id);
|
||||
Delete(u => u.Id == id);
|
||||
}
|
||||
|
||||
public IEnumerable<Role> LoadInOrgs(params int[] orgId)
|
||||
public IEnumerable<Resource> LoadInOrgs(params int[] orgId)
|
||||
{
|
||||
var result = from role in Context.Roles.Where(u => orgId.Contains(u.OrgId)) select role;
|
||||
|
||||
return result;
|
||||
var result = from resource in Context.Resources.Where(u => orgId.Contains(u.CategoryId)) select resource;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public IEnumerable<Resource> LoadResources(int pageindex, int pagesize)
|
||||
{
|
||||
return Context.Resources.OrderBy(u => u.Id).Skip((pageindex - 1) * pagesize).Take(pagesize);
|
||||
}
|
||||
|
||||
public int GetResourceCntInOrgs(params int[] orgIds)
|
||||
{
|
||||
return LoadInOrgs(orgIds).Count();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
BIN
建表&初始化数据.sql
BIN
建表&初始化数据.sql
Binary file not shown.
Loading…
Reference in New Issue
Block a user