From 000df6d1d3bab47baf77612171ff61b036390bc8 Mon Sep 17 00:00:00 2001 From: yubaolee Date: Wed, 2 Dec 2015 16:28:01 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=90=E6=A8=A1=E5=9D=97=E5=88=86?= =?UTF-8?q?=E9=85=8D=E6=8C=89=E9=92=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- OpenAuth.App/ModuleElementManagerApp.cs | 53 ++++++++++++++ OpenAuth.App/OpenAuth.App.csproj | 1 + OpenAuth.Mvc/AutofacExt.cs | 10 +++ OpenAuth.Mvc/Controllers/BaseController.cs | 4 +- .../ModuleElementManagerController.cs | 69 +++++++++++++++++++ .../Controllers/ModuleManagerController.cs | 3 +- OpenAuth.Mvc/OpenAuth.Mvc.csproj | 2 + OpenAuth.Mvc/Views/Home/Index.cshtml | 11 ++- OpenAuth.Mvc/Views/Home/Main.cshtml | 11 ++- .../Views/ModuleElementManager/Index.cshtml | 61 ++++++++++++++++ OpenAuth.Mvc/Views/ModuleManager/Index.cshtml | 16 ++++- OpenAuth.Mvc/Views/RoleManager/Index.cshtml | 2 +- OpenAuth.Mvc/Views/UserManager/Index.cshtml | 4 +- 13 files changed, 228 insertions(+), 19 deletions(-) create mode 100644 OpenAuth.App/ModuleElementManagerApp.cs create mode 100644 OpenAuth.Mvc/Controllers/ModuleElementManagerController.cs create mode 100644 OpenAuth.Mvc/Views/ModuleElementManager/Index.cshtml diff --git a/OpenAuth.App/ModuleElementManagerApp.cs b/OpenAuth.App/ModuleElementManagerApp.cs new file mode 100644 index 00000000..3352abc7 --- /dev/null +++ b/OpenAuth.App/ModuleElementManagerApp.cs @@ -0,0 +1,53 @@ +// *********************************************************************** +// 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); + } + } +} diff --git a/OpenAuth.App/OpenAuth.App.csproj b/OpenAuth.App/OpenAuth.App.csproj index a68b7dfd..bb908b5b 100644 --- a/OpenAuth.App/OpenAuth.App.csproj +++ b/OpenAuth.App/OpenAuth.App.csproj @@ -44,6 +44,7 @@ + diff --git a/OpenAuth.Mvc/AutofacExt.cs b/OpenAuth.Mvc/AutofacExt.cs index 40d4991e..0b74e57d 100644 --- a/OpenAuth.Mvc/AutofacExt.cs +++ b/OpenAuth.Mvc/AutofacExt.cs @@ -18,6 +18,8 @@ using Autofac.Integration.Mvc; using OpenAuth.App; using System.Reflection; using System.Web.Mvc; +using OpenAuth.Domain.Interface; +using OpenAuth.Repository; namespace OpenAuth.Mvc { @@ -27,12 +29,20 @@ namespace OpenAuth.Mvc { var builder = new ContainerBuilder(); + //ע + builder.RegisterGeneric(typeof(BaseRepository<>)).As(typeof(IRepository<>)); + + //Ӧòע builder.RegisterModule(new ConfigurationSettingsReader("autofac")); builder.RegisterType(); builder.RegisterType(); builder.RegisterType(); builder.RegisterType(); builder.RegisterType(); + builder.RegisterType(); + + + // Register your MVC controllers. builder.RegisterControllers(typeof(MvcApplication).Assembly); diff --git a/OpenAuth.Mvc/Controllers/BaseController.cs b/OpenAuth.Mvc/Controllers/BaseController.cs index e1b87e98..851c59e3 100644 --- a/OpenAuth.Mvc/Controllers/BaseController.cs +++ b/OpenAuth.Mvc/Controllers/BaseController.cs @@ -30,7 +30,7 @@ namespace OpenAuth.Mvc.Controllers var loginUser = SessionHelper.GetSessionUser(); if (loginUser == null) { - Response.Redirect("/Login/Index"); + filterContext.Result = new RedirectResult("/Login/Index"); return; } @@ -43,7 +43,7 @@ namespace OpenAuth.Mvc.Controllers && !url.Contains("Git") && !loginUser.Modules.Any(u => url.Contains(u.Url))) { - Response.Redirect("/Error/NoAccess"); + filterContext.Result = new RedirectResult("/Login/Index"); return; } } diff --git a/OpenAuth.Mvc/Controllers/ModuleElementManagerController.cs b/OpenAuth.Mvc/Controllers/ModuleElementManagerController.cs new file mode 100644 index 00000000..375dde94 --- /dev/null +++ b/OpenAuth.Mvc/Controllers/ModuleElementManagerController.cs @@ -0,0 +1,69 @@ +// *********************************************************************** +// Assembly : OpenAuth.Mvc +// 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; +using System.Web.Mvc; +using Infrastructure; +using OpenAuth.App; +using OpenAuth.Domain; +using OpenAuth.Mvc.Models; + +namespace OpenAuth.Mvc.Controllers +{ + public class ModuleElementManagerController : Controller + { + private readonly BjuiResponse _bjuiResponse = new BjuiResponse(); + private ModuleElementManagerApp _app; + + public ModuleElementManagerController() + { + _app = (ModuleElementManagerApp) DependencyResolver.Current.GetService(typeof (ModuleElementManagerApp)); + } + + public ActionResult Index(int id = 0) + { + ViewBag.ModuleId = id; + return View(_app.LoadByModuleId(id)); + } + + [HttpPost] + public string AddOrEditButton(ModuleElement button) + { + try + { + _app.AddOrUpdate(button); + } + catch (Exception e) + { + _bjuiResponse.statusCode = "300"; + _bjuiResponse.message = e.Message; + } + return JsonHelper.Instance.Serialize(_bjuiResponse); + } + + public string DelButton(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/OpenAuth.Mvc/Controllers/ModuleManagerController.cs b/OpenAuth.Mvc/Controllers/ModuleManagerController.cs index f913dbea..090a0709 100644 --- a/OpenAuth.Mvc/Controllers/ModuleManagerController.cs +++ b/OpenAuth.Mvc/Controllers/ModuleManagerController.cs @@ -122,7 +122,7 @@ namespace OpenAuth.Mvc.Controllers return JsonHelper.Instance.Serialize(BjuiResponse); } - #region 命令操作 + #region 添加编辑模块 public ActionResult Add(int id = 0) { return View(_app.Find(id)); @@ -162,5 +162,6 @@ namespace OpenAuth.Mvc.Controllers return JsonHelper.Instance.Serialize(BjuiResponse); } #endregion + } } \ No newline at end of file diff --git a/OpenAuth.Mvc/OpenAuth.Mvc.csproj b/OpenAuth.Mvc/OpenAuth.Mvc.csproj index 074fb901..f0f4014e 100644 --- a/OpenAuth.Mvc/OpenAuth.Mvc.csproj +++ b/OpenAuth.Mvc/OpenAuth.Mvc.csproj @@ -128,6 +128,7 @@ + @@ -622,6 +623,7 @@ + diff --git a/OpenAuth.Mvc/Views/Home/Index.cshtml b/OpenAuth.Mvc/Views/Home/Index.cshtml index 7711b262..3f1dab32 100644 --- a/OpenAuth.Mvc/Views/Home/Index.cshtml +++ b/OpenAuth.Mvc/Views/Home/Index.cshtml @@ -171,7 +171,8 @@