diff --git a/CodeSmith/Add.cshtml.cst b/CodeSmith/Add.cshtml.cst
new file mode 100644
index 00000000..d4157f11
--- /dev/null
+++ b/CodeSmith/Add.cshtml.cst
@@ -0,0 +1,140 @@
+<%--
+Name: 添加界面
+Author: yubaolee
+Description: 任务对象界面
+--%>
+<%@ 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="级联字段" %>
+<%@ Map Name="CSharpAlias" Src="System-CSharpAlias" Description="System to C# Type Map" %>
+<%@ Assembly Name="SchemaExplorer" %>
+<%@ Import Namespace="SchemaExplorer" %>
+
+<%if(NeedViewModel){ %>
+@model OpenAuth.App.ViewModel.<%=GetModelName()%>
+<%} else{ %>
+@model OpenAuth.Domain.<%=GetModelName()%>
+<%} %>
+@{
+ ViewBag.Title = "<%=GetModelName()%>编辑界面";
+ Layout = null;
+}
+
-
-<%if(NeedViewModel){ %>
-@model OpenAuth.App.ViewModel.<%=GetModelName()%>
-<%} else{ %>
-@model OpenAuth.Domain.<%=GetModelName()%>
-<%} %>
-@{
- ViewBag.Title = "<%=GetModelName()%>编辑界面";
- Layout = null;
-}
-
-
-
-
-
\ No newline at end of file
diff --git a/CodeSmith/带其他级联/Application.cst b/CodeSmith/带其他级联/Application.cst
deleted file mode 100644
index d6120175..00000000
--- a/CodeSmith/带其他级联/Application.cst
+++ /dev/null
@@ -1,138 +0,0 @@
-<%--
-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" %>
-
-
-<%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();
- }
-
- ///
- /// 加载一个节点下面的一个或全部<%=GetModelName()%>s
- ///
- 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
- };
- }
-
- ///
- /// 获取当前节点的所有下级节点
- ///
- 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()%>);
- }
-
- }
-
-
- }
-}
\ No newline at end of file
diff --git a/CodeSmith/带其他级联/Controller.cst b/CodeSmith/带其他级联/Controller.cst
deleted file mode 100644
index 6e45e6a8..00000000
--- a/CodeSmith/带其他级联/Controller.cst
+++ /dev/null
@@ -1,110 +0,0 @@
-<%--
-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" %>
-
-
-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);
- }
-
- ///
- /// 加载节点下面的所有<%=ModuleName %>s
- ///
- 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);
- }
-
-
- }
-}
\ No newline at end of file
diff --git a/CodeSmith/带其他级联/IRepository.cst b/CodeSmith/带其他级联/IRepository.cst
deleted file mode 100644
index 4e1ec96c..00000000
--- a/CodeSmith/带其他级联/IRepository.cst
+++ /dev/null
@@ -1,28 +0,0 @@
-<%--
-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);
-
- }
-}
\ No newline at end of file
diff --git a/CodeSmith/本身带级联/Add.cshtml.cst b/CodeSmith/本身带级联/Add.cshtml.cst
deleted file mode 100644
index 5b4f093e..00000000
--- a/CodeSmith/本身带级联/Add.cshtml.cst
+++ /dev/null
@@ -1,145 +0,0 @@
-<%--
-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" %>
-
-<%if(NeedViewModel){ %>
-@model OpenAuth.App.ViewModel.<%=GetModelName()%>
-<%} else{ %>
-@model OpenAuth.Domain.<%=GetModelName()%>
-<%} %>
-@{
- ViewBag.Title = "<%=GetModelName()%>编辑界面";
- Layout = null;
-}
-
-
-
-
-
\ No newline at end of file
diff --git a/OpenAuth.App/LoginApp.cs b/OpenAuth.App/LoginApp.cs
index 259ad2ae..8206a415 100644
--- a/OpenAuth.App/LoginApp.cs
+++ b/OpenAuth.App/LoginApp.cs
@@ -14,17 +14,20 @@ namespace OpenAuth.App
private IUserRepository _repository;
private IModuleRepository _moduleRepository;
private IRelevanceRepository _relevanceRepository;
- private IRepository
_moduleElementRepository;
+ private IRepository _moduleElementRepository;
+ private IResourceRepository _resourceRepository;
public LoginApp(IUserRepository repository,
IModuleRepository moduleRepository,
IRelevanceRepository relevanceRepository,
- IRepository moduleElementRepository )
+ IRepository moduleElementRepository,
+ IResourceRepository resourceRepository)
{
_repository = repository;
_moduleRepository = moduleRepository;
_relevanceRepository = relevanceRepository;
_moduleElementRepository = moduleElementRepository;
+ _resourceRepository = resourceRepository;
}
public LoginUserVM Login(string userName, string password)
@@ -64,8 +67,15 @@ namespace OpenAuth.App
{
module.Elements = _moduleElementRepository.Find(u => u.ModuleId == module.Id && elementIds.Contains( u.Id)).ToList();
}
-
- return loginVM;
+
+ //ûɫԼ䵽ԴID
+ var resourceIds = _relevanceRepository.Find(
+ u =>
+ (u.FirstId == user.Id && u.Key == "UserResource") ||
+ (u.Key == "RoleResource" && userRoleIds.Contains(u.FirstId))).Select(u => u.SecondId).ToList();
+ loginVM.Resources = _resourceRepository.Find(u => resourceIds.Contains(u.Id)).ToList();
+
+ return loginVM;
}
///
@@ -86,6 +96,8 @@ namespace OpenAuth.App
{
module.Elements = _moduleElementRepository.Find(u => u.ModuleId == module.Id).ToList();
}
+
+ loginUser.Resources = _resourceRepository.Find(null).ToList();
return loginUser;
}
}
diff --git a/OpenAuth.App/RoleManagerApp.cs b/OpenAuth.App/RoleManagerApp.cs
index e73673e1..90a8c438 100644
--- a/OpenAuth.App/RoleManagerApp.cs
+++ b/OpenAuth.App/RoleManagerApp.cs
@@ -96,9 +96,9 @@ namespace OpenAuth.App
}
}
- public List LoadWithUser(int userId)
+ public List LoadForOrgAndUser(int orgId, int userId)
{
- var roleIds = _repository.Find(null).ToList();
+ var roleIds = _repository.Find(u =>u.OrgId == orgId).ToList();
var rolevms = new List();
foreach (var role in roleIds)
{
diff --git a/OpenAuth.App/ViewModel/LoginUserVM.cs b/OpenAuth.App/ViewModel/LoginUserVM.cs
index b8ea1a7c..71c45f0b 100644
--- a/OpenAuth.App/ViewModel/LoginUserVM.cs
+++ b/OpenAuth.App/ViewModel/LoginUserVM.cs
@@ -27,6 +27,14 @@ namespace OpenAuth.App.ViewModel
/// 用户可以访问到的模块(包括所属角色与自己的所有模块)
///
public List Modules { get; set; }
+
+ //用户可以访问的资源
+ public List Resources { get; set; }
+
+ ///
+ /// 用户所属机构
+ ///
+ public List Orgs { get; set; }
}
}
diff --git a/OpenAuth.Mvc/Controllers/RoleManagerController.cs b/OpenAuth.Mvc/Controllers/RoleManagerController.cs
index ab8fbabb..10394b0c 100644
--- a/OpenAuth.Mvc/Controllers/RoleManagerController.cs
+++ b/OpenAuth.Mvc/Controllers/RoleManagerController.cs
@@ -71,10 +71,16 @@ namespace OpenAuth.Mvc.Controllers
}
#region 为用户设置角色界面
- public ActionResult LookUpMulti(int userId)
+
+ public ActionResult LookupMulti(int userId)
{
ViewBag.UserId = userId;
- return View(_app.LoadWithUser(userId));
+ return View();
+ }
+
+ public string LoadForOrgAndUser(int orgId, int userId)
+ {
+ return JsonHelper.Instance.Serialize(_app.LoadForOrgAndUser(orgId, userId));
}
public string AccessRoles(int userId, string ids)
@@ -83,6 +89,7 @@ namespace OpenAuth.Mvc.Controllers
_app.AccessRole(userId, roleids);
return JsonHelper.Instance.Serialize(BjuiResponse);
}
- #endregion
+
+ #endregion 为用户设置角色界面
}
}
\ No newline at end of file
diff --git a/OpenAuth.Mvc/OpenAuth.Mvc.csproj b/OpenAuth.Mvc/OpenAuth.Mvc.csproj
index 3f75f336..4807e3a9 100644
--- a/OpenAuth.Mvc/OpenAuth.Mvc.csproj
+++ b/OpenAuth.Mvc/OpenAuth.Mvc.csproj
@@ -574,6 +574,7 @@
+
@@ -640,7 +641,6 @@
-
10.0
diff --git a/OpenAuth.Mvc/Views/RoleManager/LookupMulti.cshtml b/OpenAuth.Mvc/Views/RoleManager/LookupMulti.cshtml
index 52bc66d8..31ccc0d9 100644
--- a/OpenAuth.Mvc/Views/RoleManager/LookupMulti.cshtml
+++ b/OpenAuth.Mvc/Views/RoleManager/LookupMulti.cshtml
@@ -1,77 +1,126 @@
-@model List
-@{
- ViewBag.Title = "title";
- Layout = null;
+@{
+ string _prefix = "assignRoleForUser";
+ var _treeId = _prefix + "Tree";
+ var _gridId = _prefix + "Grid";
+ var _treeDetail = _prefix + "Detail";
}
-@*