From 12bd4591bbfe1e26f1163f5c807917e149344331 Mon Sep 17 00:00:00 2001 From: yubaolee Date: Sat, 21 Nov 2015 23:56:39 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0Module=E6=A8=A1=E5=9D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- OpenAuth.App/ModuleManagerApp.cs | 99 ++++++++ OpenAuth.App/OpenAuth.App.csproj | 1 + .../Interface/IModuleRepository.cs | 18 ++ OpenAuth.Domain/OpenAuth.Domain.csproj | 1 + OpenAuth.Mvc/AutofacExt.cs | 1 + .../Controllers/ModuleManagerController.cs | 74 +++++- OpenAuth.Mvc/OpenAuth.Mvc.csproj | 3 + OpenAuth.Mvc/Views/Home/Index.cshtml | 1 + OpenAuth.Mvc/Views/ModuleManager/Add.cshtml | 217 ++++++++++++++++++ OpenAuth.Mvc/Views/ModuleManager/Index.cshtml | 195 ++++++++++++++++ OpenAuth.Mvc/Web.config | 1 + OpenAuth.Repository/ModuleRepository.cs | 44 ++++ .../OpenAuth.Repository.csproj | 1 + 13 files changed, 650 insertions(+), 6 deletions(-) create mode 100644 OpenAuth.App/ModuleManagerApp.cs create mode 100644 OpenAuth.Domain/Interface/IModuleRepository.cs create mode 100644 OpenAuth.Mvc/Views/ModuleManager/Add.cshtml create mode 100644 OpenAuth.Mvc/Views/ModuleManager/Index.cshtml create mode 100644 OpenAuth.Repository/ModuleRepository.cs diff --git a/OpenAuth.App/ModuleManagerApp.cs b/OpenAuth.App/ModuleManagerApp.cs new file mode 100644 index 00000000..b300773d --- /dev/null +++ b/OpenAuth.App/ModuleManagerApp.cs @@ -0,0 +1,99 @@ + +using OpenAuth.Domain; +using OpenAuth.Domain.Interface; +using System; +using System.Collections.Generic; +using System.Linq; + +namespace OpenAuth.App +{ + public class ModuleManagerApp + { + private IModuleRepository _repository; + private IOrgRepository _orgRepository; + + public ModuleManagerApp(IModuleRepository repository, + IOrgRepository orgRepository) + { + _repository = repository; + _orgRepository = orgRepository; + } + + public int GetModuleCntInOrg(int orgId) + { + if (orgId == 0) + { + return _repository.Find(null).Count(); + } + else + { + return _repository.GetModuleCntInOrgs(GetSubOrgIds(orgId)); + } + } + + /// + /// 加载一个部门及子部门全部Modules + /// + public dynamic Load(int orgId, int pageindex, int pagesize) + { + IEnumerable Modules; + int total = 0; + if (orgId == 0) + { + Modules = _repository.LoadModules(pageindex, pagesize); + total = _repository.GetCount(); + } + else + { + Modules = _repository.LoadInOrgs(pageindex, pagesize,GetSubOrgIds(orgId)); + total = _repository.GetModuleCntInOrgs(orgId); + } + + return new + { + total = total, + list = Modules, + 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 Module Find(int id) + { + var module = _repository.FindSingle(u => u.Id == id); + if (module == null) return new Module(); + + return module; + } + + public void Delete(int id) + { + _repository.Delete(id); + } + + public void AddOrUpdate(Module model) + { + Module module = model; + if (module.Id == 0) + { + _repository.Add(module); + } + else + { + _repository.Update(module); + } + + } + + + } +} \ No newline at end of file diff --git a/OpenAuth.App/OpenAuth.App.csproj b/OpenAuth.App/OpenAuth.App.csproj index 747864a9..3b03fa3a 100644 --- a/OpenAuth.App/OpenAuth.App.csproj +++ b/OpenAuth.App/OpenAuth.App.csproj @@ -44,6 +44,7 @@ + diff --git a/OpenAuth.Domain/Interface/IModuleRepository.cs b/OpenAuth.Domain/Interface/IModuleRepository.cs new file mode 100644 index 00000000..ff628853 --- /dev/null +++ b/OpenAuth.Domain/Interface/IModuleRepository.cs @@ -0,0 +1,18 @@ +using System.Collections.Generic; +using System.Linq; + +namespace OpenAuth.Domain.Interface +{ + public interface IModuleRepository :IRepository + { + IEnumerable LoadModules(int pageindex, int pagesize); + + IEnumerable LoadInOrgs(params int[] orgId); + int GetModuleCntInOrgs(params int[] orgIds); + IEnumerable LoadInOrgs(int pageindex, int pagesize, params int[] orgIds); + + + void Delete(int id); + + } +} \ No newline at end of file diff --git a/OpenAuth.Domain/OpenAuth.Domain.csproj b/OpenAuth.Domain/OpenAuth.Domain.csproj index 511dd859..4b7e7082 100644 --- a/OpenAuth.Domain/OpenAuth.Domain.csproj +++ b/OpenAuth.Domain/OpenAuth.Domain.csproj @@ -42,6 +42,7 @@ + diff --git a/OpenAuth.Mvc/AutofacExt.cs b/OpenAuth.Mvc/AutofacExt.cs index e5e00b7f..5b1203fd 100644 --- a/OpenAuth.Mvc/AutofacExt.cs +++ b/OpenAuth.Mvc/AutofacExt.cs @@ -32,6 +32,7 @@ namespace OpenAuth.Mvc builder.RegisterType(); builder.RegisterType(); builder.RegisterType(); + builder.RegisterType(); // Register your MVC controllers. builder.RegisterControllers(typeof(MvcApplication).Assembly); diff --git a/OpenAuth.Mvc/Controllers/ModuleManagerController.cs b/OpenAuth.Mvc/Controllers/ModuleManagerController.cs index 380fec5f..827d89cc 100644 --- a/OpenAuth.Mvc/Controllers/ModuleManagerController.cs +++ b/OpenAuth.Mvc/Controllers/ModuleManagerController.cs @@ -1,18 +1,80 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Web; + +using System; using System.Web.Mvc; +using Infrastructure; +using OpenAuth.App; +using OpenAuth.Domain; namespace OpenAuth.Mvc.Controllers { public class ModuleManagerController : BaseController { + private ModuleManagerApp _app; + + public ModuleManagerController() + { + _app = (ModuleManagerApp)DependencyResolver.Current.GetService(typeof(ModuleManagerApp)); + } + // - // GET: /Modu/ + // GET: /ModuleManager/ public ActionResult Index() { return View(); } - } + + public ActionResult Add(int id = 0) + { + return View(_app.Find(id)); + } + + //添加或修改组织 + [HttpPost] + public string Add(Module model) + { + try + { + _app.AddOrUpdate(model); + + } + catch (Exception ex) + { + BjuiResponse.statusCode = "300"; + BjuiResponse.message = ex.Message; + } + return JsonHelper.Instance.Serialize(BjuiResponse); + } + + /// + /// 加载组织下面的所有用户 + /// + public string Load(int orgId, int pageCurrent = 1, int pageSize = 30) + { + return JsonHelper.Instance.Serialize(_app.Load(orgId, pageCurrent, pageSize)); + } + + //获取组织下面用户个数 + public int GetCount(int orgId) + { + return _app.GetModuleCntInOrg(orgId); + } + + public string Delete(string Id) + { + try + { + foreach (var obj in Id.Split(',')) + { + _app.Delete(int.Parse(obj)); + } + } + catch (Exception e) + { + BjuiResponse.statusCode = "300"; + BjuiResponse.message = e.Message; + } + + return JsonHelper.Instance.Serialize(BjuiResponse); + } + } } \ No newline at end of file diff --git a/OpenAuth.Mvc/OpenAuth.Mvc.csproj b/OpenAuth.Mvc/OpenAuth.Mvc.csproj index 1a47fbb4..acd4c075 100644 --- a/OpenAuth.Mvc/OpenAuth.Mvc.csproj +++ b/OpenAuth.Mvc/OpenAuth.Mvc.csproj @@ -126,6 +126,7 @@ + @@ -614,6 +615,8 @@ + + diff --git a/OpenAuth.Mvc/Views/Home/Index.cshtml b/OpenAuth.Mvc/Views/Home/Index.cshtml index 54c2775b..42dda811 100644 --- a/OpenAuth.Mvc/Views/Home/Index.cshtml +++ b/OpenAuth.Mvc/Views/Home/Index.cshtml @@ -207,6 +207,7 @@
  • 机构管理
  • 用户管理
  • 角色管理
  • +
  • 模块管理
  • diff --git a/OpenAuth.Mvc/Views/ModuleManager/Add.cshtml b/OpenAuth.Mvc/Views/ModuleManager/Add.cshtml new file mode 100644 index 00000000..a4c085d6 --- /dev/null +++ b/OpenAuth.Mvc/Views/ModuleManager/Add.cshtml @@ -0,0 +1,217 @@ + +@model OpenAuth.App.ViewModel.Module +@{ + ViewBag.Title = "title"; + Layout = null; +} + +
    +
    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

    * 添加

    + @Html.HiddenFor(m =>m.Id) +
    + + + + +
    + + + + +
    + + + + +
    + + + + +
    + + + + +
    + +
    + + + +
    + +
    + + + +
    + + + + +
    + + + + +
    + + + + +
    + + + + +
    + + + + +
    + + + +
      +
    +
    +
    +
    + + + \ No newline at end of file diff --git a/OpenAuth.Mvc/Views/ModuleManager/Index.cshtml b/OpenAuth.Mvc/Views/ModuleManager/Index.cshtml new file mode 100644 index 00000000..65aa8579 --- /dev/null +++ b/OpenAuth.Mvc/Views/ModuleManager/Index.cshtml @@ -0,0 +1,195 @@ +@{ + string _prefix = "Module"; + var _treeId = _prefix + "Tree"; + var _gridId = _prefix + "Grid"; + var _treeDetail = _prefix + "Detail"; +} +
    +
    +
    +
      +
      + +
      +
      +
      +
      + + + diff --git a/OpenAuth.Mvc/Web.config b/OpenAuth.Mvc/Web.config index c56c9128..b90c24df 100644 --- a/OpenAuth.Mvc/Web.config +++ b/OpenAuth.Mvc/Web.config @@ -42,6 +42,7 @@ + diff --git a/OpenAuth.Repository/ModuleRepository.cs b/OpenAuth.Repository/ModuleRepository.cs new file mode 100644 index 00000000..3b1080b7 --- /dev/null +++ b/OpenAuth.Repository/ModuleRepository.cs @@ -0,0 +1,44 @@ +using System.Collections.Generic; +using System.Linq; +using OpenAuth.Domain; +using OpenAuth.Domain.Interface; + +namespace OpenAuth.Repository +{ + public class ModuleRepository :BaseRepository, IModuleRepository + { + public IEnumerable LoadModules(int pageindex, int pagesize) + { + return Context.Modules.OrderBy(u => u.Id).Skip((pageindex - 1) * pagesize).Take(pagesize); + } + + public int GetRoleCntInOrgs(params int[] orgIds) + { + return LoadInOrgs(orgIds).Count(); + } + + public int GetModuleCntInOrgs(params int[] orgIds) + { + return LoadInOrgs(orgIds).Count(); + } + + + public IEnumerable 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 LoadInOrgs(params int[] orgId) + { + var result = from role in Context.Modules.Where(u => orgId.Contains(u.ParentId)) select role; + + return result; + + } + } +} diff --git a/OpenAuth.Repository/OpenAuth.Repository.csproj b/OpenAuth.Repository/OpenAuth.Repository.csproj index 7f3c4d67..0e6324cd 100644 --- a/OpenAuth.Repository/OpenAuth.Repository.csproj +++ b/OpenAuth.Repository/OpenAuth.Repository.csproj @@ -69,6 +69,7 @@ +