diff --git a/OpenAuth.App/ModuleElementManagerApp.cs b/OpenAuth.App/ModuleElementManagerApp.cs
index 3352abc7..7875e161 100644
--- a/OpenAuth.App/ModuleElementManagerApp.cs
+++ b/OpenAuth.App/ModuleElementManagerApp.cs
@@ -1,53 +1,110 @@
-// ***********************************************************************
-// Assembly : OpenAuth.App
-// Author : Yubao Li
-// Created : 12-02-2015
-//
-// Last Modified By : Yubao Li
-// Last Modified On : 12-02-2015
-// ***********************************************************************
-//
-// Copyright (c) . All rights reserved.
-//
-// 模块元素
-// ***********************************************************************
-
-using System.Collections.Generic;
-using OpenAuth.Domain;
-using OpenAuth.Domain.Interface;
-
-namespace OpenAuth.App
-{
- public class ModuleElementManagerApp
- {
- private readonly IRepository _repository;
-
- public ModuleElementManagerApp(IRepository repository)
- {
- _repository = repository;
- }
-
- public void AddOrUpdate(ModuleElement model)
- {
- if (model.Id == 0)
- {
- _repository.Add(model);
- }
- else
- {
- _repository.Update(model);
- }
- }
-
- public IEnumerable LoadByModuleId(int id)
- {
- var modules = _repository.Find(u => u.ModuleId == id);
- return modules;
- }
-
- public void Delete(int id)
- {
- _repository.Delete(u =>u.Id ==id);
- }
- }
-}
+// ***********************************************************************
+// Assembly : OpenAuth.App
+// Author : Yubao Li
+// Created : 12-02-2015
+//
+// Last Modified By : Yubao Li
+// Last Modified On : 12-02-2015
+// ***********************************************************************
+//
+// Copyright (c) . All rights reserved.
+//
+// 模块元素
+// ***********************************************************************
+
+using System.Collections.Generic;
+using System.Linq;
+using Infrastructure;
+using OpenAuth.App.ViewModel;
+using OpenAuth.Domain;
+using OpenAuth.Domain.Interface;
+
+namespace OpenAuth.App
+{
+ public class ModuleElementManagerApp
+ {
+ private readonly IRepository _repository;
+ private IModuleRepository _moduleRepository;
+ private IRelevanceRepository _relevanceRepository;
+
+ public ModuleElementManagerApp(IRepository repository,
+ IRelevanceRepository relevanceRepository,
+ IModuleRepository moduleRepository )
+ {
+ _repository = repository;
+ _moduleRepository = moduleRepository;
+ _relevanceRepository = relevanceRepository;
+ }
+
+ public void AddOrUpdate(ModuleElement model)
+ {
+ if (model.Id == 0)
+ {
+ _repository.Add(model);
+ }
+ else
+ {
+ _repository.Update(model);
+ }
+ }
+
+ public IEnumerable LoadByModuleId(int id)
+ {
+ var modules = _repository.Find(u => u.ModuleId == id);
+ return modules;
+ }
+
+ ///
+ /// 获取带有授权状态的菜单列表
+ ///
+ /// 授权类型,当前有RoleElement/UserElement
+ ///
+ /// 当为RoleElement时,表示RoleId
+ /// 当为UserElement时,表示UserId
+ ///
+ /// 模块ID
+ public List LoadWithAccess(string accessType, int firstId, int moduleId)
+ {
+ //TODO:多个Repository使用的是不同的Context不能进行联表查询,要用UnitOfWork处理
+ //var results = from element in _repository.Find(u => u.ModuleId == moduleId)
+ // join module in _moduleRepository.Find(null) on element.ModuleId equals module.Id
+ // join relev in _relevanceRepository.Find(u => u.Key == accessType && u.FirstId == firstId)
+ // on element.Id equals relev.SecondId into temp
+ // from t in temp.DefaultIfEmpty()
+ // select new ModuleElementVM
+ // {
+ // DomId = element.DomId,
+ // Id = element.Id,
+ // ModuleId = element.ModuleId,
+ // ModuleName = module.Name,
+ // Name = element.Name,
+ // Accessed = t != null
+ // };
+ var listVms = new List();
+ if (moduleId == 0) return listVms;
+ string modulename = _moduleRepository.FindSingle(u => u.Id == moduleId).Name;
+
+ foreach (var element in LoadByModuleId(moduleId))
+ {
+ var accessed = _relevanceRepository.FindSingle(u =>u.Key == accessType
+ && u.FirstId == firstId && u.SecondId == element.Id);
+ ModuleElementVM vm = new ModuleElementVM
+ {
+ Id = element.Id,
+ Name = element.Name,
+ ModuleId = element.ModuleId,
+ DomId = element.DomId,
+ ModuleName = modulename,
+ Accessed = accessed != null
+ };
+ listVms.Add(vm);
+ }
+ return listVms;
+ }
+
+ public void Delete(int id)
+ {
+ _repository.Delete(u =>u.Id ==id);
+ }
+ }
+}
diff --git a/OpenAuth.App/ModuleManagerApp.cs b/OpenAuth.App/ModuleManagerApp.cs
index e81c8166..0b877a07 100644
--- a/OpenAuth.App/ModuleManagerApp.cs
+++ b/OpenAuth.App/ModuleManagerApp.cs
@@ -115,7 +115,7 @@ namespace OpenAuth.App
_relevanceRepository.Find(u => u.FirstId == userId && u.Key == "UserModule")
.Select(u => u.SecondId)
.ToList();
- if (!moduleIds.Any()) return null;
+ if (!moduleIds.Any()) return new List();
return _repository.Find(u => moduleIds.Contains(u.Id)).ToList();
}
@@ -140,7 +140,7 @@ namespace OpenAuth.App
_relevanceRepository.Find(u => u.FirstId == roleId && u.Key == "RoleModule")
.Select(u => u.SecondId)
.ToList();
- if (!moduleIds.Any()) return null;
+ if (!moduleIds.Any()) return new List();
return _repository.Find(u => moduleIds.Contains(u.Id)).ToList();
}
diff --git a/OpenAuth.App/OpenAuth.App.csproj b/OpenAuth.App/OpenAuth.App.csproj
index bb908b5b..1eaf6be2 100644
--- a/OpenAuth.App/OpenAuth.App.csproj
+++ b/OpenAuth.App/OpenAuth.App.csproj
@@ -51,6 +51,7 @@
+
diff --git a/OpenAuth.App/RoleManagerApp.cs b/OpenAuth.App/RoleManagerApp.cs
index b9f212f9..e73673e1 100644
--- a/OpenAuth.App/RoleManagerApp.cs
+++ b/OpenAuth.App/RoleManagerApp.cs
@@ -39,6 +39,7 @@ namespace OpenAuth.App
///
public dynamic Load(int orgId, int pageindex, int pagesize)
{
+ if (pageindex < 1) pageindex = 1; //TODO:如果列表为空新增加一个用户后,前端会传一个0过来,奇怪??
IEnumerable roles;
int total = 0;
if (orgId == 0)
diff --git a/OpenAuth.App/UserManagerApp.cs b/OpenAuth.App/UserManagerApp.cs
index 5b2232b2..f6905d14 100644
--- a/OpenAuth.App/UserManagerApp.cs
+++ b/OpenAuth.App/UserManagerApp.cs
@@ -39,7 +39,7 @@ namespace OpenAuth.App
///
public dynamic Load(int orgId, int pageindex, int pagesize)
{
- if (pageindex < 1) pageindex = 1; //如果列表为空新增加一个用户后,前端会传一个0过来,奇怪??
+ if (pageindex < 1) pageindex = 1; //TODO:如果列表为空新增加一个用户后,前端会传一个0过来,奇怪??
IEnumerable users;
int total = 0;
if (orgId == 0)
diff --git a/OpenAuth.App/ViewModel/ModuleElementVM.cs b/OpenAuth.App/ViewModel/ModuleElementVM.cs
new file mode 100644
index 00000000..09e37dbd
--- /dev/null
+++ b/OpenAuth.App/ViewModel/ModuleElementVM.cs
@@ -0,0 +1,49 @@
+namespace OpenAuth.App.ViewModel
+{
+ ///
+ /// 用户ID
+ ///
+ public class ModuleElementVM
+ {
+ ///
+ /// 用户ID
+ ///
+ ///
+ public int Id { get; set; }
+
+ ///
+ /// DOM ID
+ ///
+ ///
+ public string DomId { get; set; }
+
+ ///
+ /// 组织名称
+ ///
+ ///
+ public string Name { get; set; }
+
+ //模块ID
+ public int ModuleId { get; set; }
+
+ ///
+ /// 所属模块名称
+ ///
+ public string ModuleName { get; set; }
+
+ ///
+ /// 授权状态
+ ///
+ public bool Accessed { get; set; }
+
+ public ModuleElementVM()
+ {
+ this.Id = 0;
+ this.DomId = string.Empty;
+ this.Name = string.Empty;
+ this.ModuleId = 0;
+ this.ModuleName = string.Empty;
+ this.Accessed = false;
+ }
+ }
+}
\ No newline at end of file
diff --git a/OpenAuth.Mvc/Controllers/ModuleElementManagerController.cs b/OpenAuth.Mvc/Controllers/ModuleElementManagerController.cs
index 5960026f..8453879e 100644
--- a/OpenAuth.Mvc/Controllers/ModuleElementManagerController.cs
+++ b/OpenAuth.Mvc/Controllers/ModuleElementManagerController.cs
@@ -13,10 +13,12 @@
// ***********************************************************************
using System;
+using System.Collections.Generic;
using System.Data.Entity.Validation;
using System.Web.Mvc;
using Infrastructure;
using OpenAuth.App;
+using OpenAuth.App.ViewModel;
using OpenAuth.Domain;
using OpenAuth.Mvc.Models;
@@ -68,5 +70,19 @@ namespace OpenAuth.Mvc.Controllers
}
return JsonHelper.Instance.Serialize(_bjuiResponse);
}
+
+ #region 为角色分配菜单
+
+ public ActionResult AssignForRole(int roleId)
+ {
+ ViewBag.RoleId = roleId;
+ return View();
+ }
+
+ public string Load(int roleId, int orgId)
+ {
+ return JsonHelper.Instance.Serialize(_app.LoadWithAccess("RoleElement", roleId, orgId));
+ }
+ #endregion
}
}
\ No newline at end of file
diff --git a/OpenAuth.Mvc/OpenAuth.Mvc.csproj b/OpenAuth.Mvc/OpenAuth.Mvc.csproj
index a9354dad..2bacc647 100644
--- a/OpenAuth.Mvc/OpenAuth.Mvc.csproj
+++ b/OpenAuth.Mvc/OpenAuth.Mvc.csproj
@@ -625,6 +625,7 @@
+
diff --git a/OpenAuth.Mvc/Views/ModuleElementManager/AssignForRole.cshtml b/OpenAuth.Mvc/Views/ModuleElementManager/AssignForRole.cshtml
new file mode 100644
index 00000000..9eb96c94
--- /dev/null
+++ b/OpenAuth.Mvc/Views/ModuleElementManager/AssignForRole.cshtml
@@ -0,0 +1,132 @@
+@{
+ string _prefix = "assignForRole";
+ var _treeId = _prefix + "Tree";
+ var _gridId = _prefix + "Grid";
+ var _treeDetail = _prefix + "Detail";
+}
+
+
+
+
+
\ No newline at end of file
diff --git a/OpenAuth.Mvc/Views/RoleManager/Index.cshtml b/OpenAuth.Mvc/Views/RoleManager/Index.cshtml
index e880931e..3db10d59 100644
--- a/OpenAuth.Mvc/Views/RoleManager/Index.cshtml
+++ b/OpenAuth.Mvc/Views/RoleManager/Index.cshtml
@@ -170,5 +170,19 @@
});
}
+ //为角色分配菜单
+ function openAssignElement(obj) {
+ var selected = getSelected(gridid, 2);
+ if (selected == null) return;
+
+ $(obj).dialog({
+ id: 'assignElement',
+ url: '/ModuleElementManager/AssignForRole?roleId=' + selected,
+ title: '为角色分配菜单',
+ width: 700,
+ height:380
+ });
+ }
+
//@@ sourceURL=RoleManagerIndex.js