From fc7c568b3a3c986191ec82ed0b70bec988cbb15c Mon Sep 17 00:00:00 2001 From: yubaolee Date: Thu, 26 Nov 2015 23:09:25 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=90=E7=9B=B4=E6=8E=A5=E4=B8=BA?= =?UTF-8?q?=E7=94=A8=E6=88=B7=E5=88=86=E9=85=8D=E6=A8=A1=E5=9D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- OpenAuth.App/UserManagerApp.cs | 12 ++++- .../Interface/IUserModuleRepository.cs | 14 +++++ OpenAuth.Domain/OpenAuth.Domain.csproj | 1 + .../Controllers/UserManagerController.cs | 20 ++++++++ OpenAuth.Mvc/Views/UserManager/Index.cshtml | 10 +++- OpenAuth.Mvc/Web.config | 1 + .../OpenAuth.Repository.csproj | 1 + OpenAuth.Repository/UserModuleRepository.cs | 51 +++++++++++++++++++ OpenAuth.UnitTest/TestUserApp.cs | 4 +- 9 files changed, 109 insertions(+), 5 deletions(-) create mode 100644 OpenAuth.Domain/Interface/IUserModuleRepository.cs create mode 100644 OpenAuth.Repository/UserModuleRepository.cs diff --git a/OpenAuth.App/UserManagerApp.cs b/OpenAuth.App/UserManagerApp.cs index ea284d77..a3949d69 100644 --- a/OpenAuth.App/UserManagerApp.cs +++ b/OpenAuth.App/UserManagerApp.cs @@ -11,12 +11,15 @@ namespace OpenAuth.App { private IUserRepository _repository; private IOrgRepository _orgRepository; + private IUserModuleRepository _usermoduleRepository; public UserManagerApp(IUserRepository repository, - IOrgRepository orgRepository) + IOrgRepository orgRepository, + IUserModuleRepository usermoduleRepository) { _repository = repository; _orgRepository = orgRepository; + _usermoduleRepository = usermoduleRepository; } public int GetUserCntInOrg(int orgId) @@ -112,6 +115,11 @@ namespace OpenAuth.App _repository.SetOrg(user.Id, orgIds); } - + + public void AccessModules(int userId, int[] ids) + { + _usermoduleRepository.DeleteByUser(userId); + _usermoduleRepository.AddUserModule(userId, ids); + } } } \ No newline at end of file diff --git a/OpenAuth.Domain/Interface/IUserModuleRepository.cs b/OpenAuth.Domain/Interface/IUserModuleRepository.cs new file mode 100644 index 00000000..e9fcbc08 --- /dev/null +++ b/OpenAuth.Domain/Interface/IUserModuleRepository.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace OpenAuth.Domain.Interface +{ + public interface IUserModuleRepository : IRepository + { + void DeleteByUser(params int[] userIds); + void AddUserModule(int userId, params int[] moduleIds); + } +} diff --git a/OpenAuth.Domain/OpenAuth.Domain.csproj b/OpenAuth.Domain/OpenAuth.Domain.csproj index 4b7e7082..41c5ff15 100644 --- a/OpenAuth.Domain/OpenAuth.Domain.csproj +++ b/OpenAuth.Domain/OpenAuth.Domain.csproj @@ -46,6 +46,7 @@ + diff --git a/OpenAuth.Mvc/Controllers/UserManagerController.cs b/OpenAuth.Mvc/Controllers/UserManagerController.cs index 6bbe732d..5e3dc208 100644 --- a/OpenAuth.Mvc/Controllers/UserManagerController.cs +++ b/OpenAuth.Mvc/Controllers/UserManagerController.cs @@ -1,8 +1,12 @@ using System; +using System.Collections.Generic; +using System.Linq; using System.Web.Mvc; using Infrastructure; using OpenAuth.App; using OpenAuth.App.ViewModel; +using OpenAuth.Mvc.Models; +using WebGrease.Css.Extensions; namespace OpenAuth.Mvc.Controllers { @@ -69,5 +73,21 @@ namespace OpenAuth.Mvc.Controllers return JsonHelper.Instance.Serialize(BjuiResponse); } + + public string AccessModule(int userId, string moduleIds) + { + try + { + var ids = moduleIds.Split(',').Select(id => int.Parse(id)).ToArray(); + _app.AccessModules(userId, ids); + } + catch (Exception e) + { + BjuiResponse.message = e.Message; + BjuiResponse.statusCode = "300"; + } + + return JsonHelper.Instance.Serialize(BjuiResponse); + } } } \ No newline at end of file diff --git a/OpenAuth.Mvc/Views/UserManager/Index.cshtml b/OpenAuth.Mvc/Views/UserManager/Index.cshtml index 93d244ca..588a6256 100644 --- a/OpenAuth.Mvc/Views/UserManager/Index.cshtml +++ b/OpenAuth.Mvc/Views/UserManager/Index.cshtml @@ -30,8 +30,14 @@ var selected = getSelected(2); if (selected == null) return; - $.getJSON('UserManager/AccessModule', function (json) { - //授权操作 + $.post('UserManager/AccessModule', { userId: selected, moduleIds: accessIds }, + function (json) { + var rel = $.parseJSON(json); + if (rel.statusCode == "200") { + $(this).alertmsg('ok', rel.message); + } else { + $(this).alertmsg('error', rel.message); + } }); }); }); diff --git a/OpenAuth.Mvc/Web.config b/OpenAuth.Mvc/Web.config index b90c24df..431efff3 100644 --- a/OpenAuth.Mvc/Web.config +++ b/OpenAuth.Mvc/Web.config @@ -43,6 +43,7 @@ + diff --git a/OpenAuth.Repository/OpenAuth.Repository.csproj b/OpenAuth.Repository/OpenAuth.Repository.csproj index 0e6324cd..516a9a87 100644 --- a/OpenAuth.Repository/OpenAuth.Repository.csproj +++ b/OpenAuth.Repository/OpenAuth.Repository.csproj @@ -71,6 +71,7 @@ + diff --git a/OpenAuth.Repository/UserModuleRepository.cs b/OpenAuth.Repository/UserModuleRepository.cs new file mode 100644 index 00000000..09ea0ead --- /dev/null +++ b/OpenAuth.Repository/UserModuleRepository.cs @@ -0,0 +1,51 @@ +// *********************************************************************** +// Assembly : OpenAuth.Repository +// Author : yubaolee +// Created : 11-26-2015 +// +// Last Modified By : yubaolee +// Last Modified On : 11-26-2015 +// *********************************************************************** +// +// Copyright (c) www.cnblogs.com/yubaolee. All rights reserved. +// +// 用户菜单分配操作 +// *********************************************************************** + + +using System; +using System.Linq; +using OpenAuth.Domain; +using OpenAuth.Domain.Interface; + +namespace OpenAuth.Repository +{ + public class UserModuleRepository : BaseRepository, IUserModuleRepository + { + /// + /// 删除指定用户关联的模块 + /// + /// The user ids. + public void DeleteByUser(params int[] userIds) + { + Delete(u =>userIds.Contains(u.UserId)); + } + + /// + /// 为指定的用户分配模块 + /// + public void AddUserModule(int userId, params int[] moduleIds) + { + foreach (var moduleId in moduleIds) + { + Add(new UserModule + { + UserId = userId, + ModuleId = moduleId, + OperateTime = DateTime.Now + }); + } + Save(); + } + } +} diff --git a/OpenAuth.UnitTest/TestUserApp.cs b/OpenAuth.UnitTest/TestUserApp.cs index 4f70bc7f..1be08c32 100644 --- a/OpenAuth.UnitTest/TestUserApp.cs +++ b/OpenAuth.UnitTest/TestUserApp.cs @@ -16,7 +16,9 @@ namespace OpenAuth.UnitTest public class TestUserApp { - private UserManagerApp _app = new UserManagerApp(new UserRepository(), new OrgRepository()); + private UserManagerApp _app = new UserManagerApp(new UserRepository(), + new OrgRepository(), + new UserModuleRepository()); private string _time = DateTime.Now.ToString("HH_mm_ss_ms");