diff --git a/Bootstrap.Admin/Controllers/Api/GroupsController.cs b/Bootstrap.Admin/Controllers/Api/GroupsController.cs index 9e69d2f2..37a70576 100644 --- a/Bootstrap.Admin/Controllers/Api/GroupsController.cs +++ b/Bootstrap.Admin/Controllers/Api/GroupsController.cs @@ -2,7 +2,6 @@ using Bootstrap.DataAccess; using Longbow.Web.Mvc; using Microsoft.AspNetCore.Mvc; -using Newtonsoft.Json.Linq; using System.Collections.Generic; using System.Linq; @@ -13,93 +12,91 @@ namespace Bootstrap.Admin.Controllers.Api /// [Route("api/[controller]")] public class GroupsController : Controller - { - /// - /// - /// - /// - /// - [HttpGet] - public QueryData Get(QueryGroupOption value) - { - return value.RetrieveData(); - } - /// - /// - /// - /// - /// - [HttpGet("{id}")] - public Group Get(int id) - { - return GroupHelper.RetrieveGroups().FirstOrDefault(t => t.Id == id); - } - /// - /// - /// - /// - [HttpPost] - public bool Post([FromBody]Group value) - { - return GroupHelper.SaveGroup(value); - } + { + /// + /// + /// + /// + /// + [HttpGet] + public QueryData Get(QueryGroupOption value) + { + return value.RetrieveData(); + } + /// + /// + /// + /// + /// + [HttpGet("{id}")] + public Group Get(int id) + { + return GroupHelper.RetrieveGroups().FirstOrDefault(t => t.Id == id); + } + /// + /// + /// + /// + [HttpPost] + public bool Post([FromBody]Group value) + { + return GroupHelper.SaveGroup(value); + } /// /// /// /// [HttpDelete] - public bool Delete([FromBody]IEnumerable value) - { - return GroupHelper.DeleteGroup(value); - } - /// - /// - /// - /// - /// - /// - [HttpPost("{id}")] - public IEnumerable Post(int id, [FromBody]JObject value) - { - var ret = new List(); - dynamic json = value; - switch ((string)json.type) - { - case "user": - ret = GroupHelper.RetrieveGroupsByUserId(id).ToList(); - break; - case "role": - ret = GroupHelper.RetrieveGroupsByRoleId(id).ToList(); - break; - default: - break; - } - return ret; - } - /// - /// - /// - /// - /// - /// - [HttpPut("{id}")] - public bool Put(int id, [FromBody]JObject value) - { - var ret = false; - dynamic json = value; - string groupIds = json.groupIds; - switch ((string)json.type) - { - case "user": - ret = GroupHelper.SaveGroupsByUserId(id, groupIds); - break; - case "role": - ret = GroupHelper.SaveGroupsByRoleId(id, groupIds); - break; - default: - break; - } - return ret; - } - } + public bool Delete([FromBody]IEnumerable value) + { + return GroupHelper.DeleteGroup(value); + } + /// + /// + /// + /// + /// + /// + [HttpPost("{id}")] + public IEnumerable Post(int id, [FromQuery]string type) + { + var ret = new List(); + switch (type) + { + case "user": + ret = GroupHelper.RetrieveGroupsByUserId(id).ToList(); + break; + case "role": + ret = GroupHelper.RetrieveGroupsByRoleId(id).ToList(); + break; + default: + break; + } + return ret; + } + /// + /// + /// + /// + /// + /// + /// + [HttpPut("{id}")] + public bool Put(int id, [FromBody]IEnumerable groupIds, [FromQuery]string type) + { + var ret = false; + switch (type) + { + case "user": + ret = GroupHelper.SaveGroupsByUserId(id, groupIds); + break; + case "role": + ret = GroupHelper.SaveGroupsByRoleId(id, groupIds); + break; + default: + break; + } + return ret; + } + } } diff --git a/Bootstrap.Admin/Controllers/Api/MenusController.cs b/Bootstrap.Admin/Controllers/Api/MenusController.cs index dbe13674..fd897329 100644 --- a/Bootstrap.Admin/Controllers/Api/MenusController.cs +++ b/Bootstrap.Admin/Controllers/Api/MenusController.cs @@ -3,7 +3,6 @@ using Bootstrap.DataAccess; using Bootstrap.Security; using Longbow.Web.Mvc; using Microsoft.AspNetCore.Mvc; -using Newtonsoft.Json.Linq; using System.Collections.Generic; using System.Linq; @@ -50,11 +49,10 @@ namespace Bootstrap.Admin.Controllers.Api /// /// [HttpPost("{id}")] - public IEnumerable Post(int id, [FromBody]JObject value) + public IEnumerable Post(int id, [FromQuery]string type) { var ret = new List(); - dynamic json = value; - switch ((string)json.type) + switch (type) { case "role": ret = MenuHelper.RetrieveMenusByRoleId(id).ToList(); diff --git a/Bootstrap.Admin/Controllers/Api/RolesController.cs b/Bootstrap.Admin/Controllers/Api/RolesController.cs index dc7e600d..5213aa50 100644 --- a/Bootstrap.Admin/Controllers/Api/RolesController.cs +++ b/Bootstrap.Admin/Controllers/Api/RolesController.cs @@ -25,19 +25,17 @@ namespace Bootstrap.Admin.Controllers.Api { return value.RetrieveData(); } - /// - /// + /// 通过指定ID获得所有角色集合 /// - /// - /// + /// 用户ID/部门ID/菜单ID + /// 类型 /// [HttpPost("{id}")] - public IEnumerable Post(int id, [FromBody]JObject value) + public IEnumerable Post(int id, [FromQuery]string type) { var ret = new List(); - dynamic json = value; - switch ((string)json.type) + switch (type) { case "user": ret = RoleHelper.RetrieveRolesByUserId(id).ToList(); @@ -53,18 +51,18 @@ namespace Bootstrap.Admin.Controllers.Api } return ret; } - - /// 根据GroupID获取 + /// + /// 根据GroupID获取 /// - /// + /// + /// + /// /// [HttpPut("{id}")] - public bool Put(int id, [FromBody]JObject value) + public bool Put(int id, [FromBody]IEnumerable roleIds, [FromQuery]string type) { var ret = false; - dynamic json = value; - string roleIds = json.roleIds; - switch ((string)json.type) + switch (type) { case "user": ret = RoleHelper.SaveRolesByUserId(id, roleIds); diff --git a/Bootstrap.Admin/Controllers/Api/UsersController.cs b/Bootstrap.Admin/Controllers/Api/UsersController.cs index b61bd518..42a90f95 100644 --- a/Bootstrap.Admin/Controllers/Api/UsersController.cs +++ b/Bootstrap.Admin/Controllers/Api/UsersController.cs @@ -3,7 +3,6 @@ using Bootstrap.DataAccess; using Longbow.Web.Mvc; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; -using Newtonsoft.Json.Linq; using System; using System.Collections.Generic; using System.Linq; @@ -53,14 +52,13 @@ namespace Bootstrap.Admin.Controllers.Api /// /// /// - /// + /// /// [HttpPost("{id}")] - public IEnumerable Post(int id, [FromBody]JObject value) + public IEnumerable Post(int id, [FromQuery]string type) { var ret = new List(); - dynamic json = value; - switch ((string)json.type) + switch (type) { case "role": ret = UserHelper.RetrieveUsersByRoleId(id).ToList(); @@ -89,15 +87,14 @@ namespace Bootstrap.Admin.Controllers.Api /// /// /// - /// + /// + /// /// [HttpPut("{id}")] - public bool Put(int id, [FromBody]JObject value) + public bool Put(int id, [FromBody]IEnumerable userIds, [FromQuery]string type) { var ret = false; - dynamic json = value; - string userIds = json.userIds; - switch ((string)json.type) + switch (type) { case "role": ret = UserHelper.SaveUsersByRoleId(id, userIds); diff --git a/Bootstrap.Admin/wwwroot/js/common-scripts.js b/Bootstrap.Admin/wwwroot/js/common-scripts.js index 3f347cdc..e5de8506 100644 --- a/Bootstrap.Admin/wwwroot/js/common-scripts.js +++ b/Bootstrap.Admin/wwwroot/js/common-scripts.js @@ -40,7 +40,7 @@ nestMenu: function (callback) { var $this = $(this); $.bc({ - id: 0, url: Menu.url, data: { type: "user" }, method: "post", + id: 0, url: Menu.url, query: { type: "user" }, method: "post", callback: function (result) { var html = ""; if ($.isArray(result)) html = cascadeMenu(result); diff --git a/Bootstrap.Admin/wwwroot/js/groups.js b/Bootstrap.Admin/wwwroot/js/groups.js index 57b09bb6..3be3d97e 100644 --- a/Bootstrap.Admin/wwwroot/js/groups.js +++ b/Bootstrap.Admin/wwwroot/js/groups.js @@ -17,7 +17,7 @@ events: { '#btn_assignRole': function (row) { $.bc({ - id: row.Id, url: Role.url, data: { type: "group" }, method: "post", + id: row.Id, url: Role.url, query: { type: "group" }, method: "post", callback: function (result) { var htmlTemplate = this.htmlTemplate; var html = $.map(result, function (element, index) { @@ -33,7 +33,7 @@ }, '#btn_assignUser': function (row) { $.bc({ - id: row.Id, url: User.url, data: { type: "group" }, method: "post", + id: row.Id, url: User.url, query: { type: "group" }, method: "post", callback: function (result) { var htmlTemplate = this.htmlTemplate; var html = $.map(result, function (element, index) { @@ -51,15 +51,15 @@ var groupId = row.Id; var roleIds = $dialogRole.find('input:checked').map(function (index, element) { return $(element).val(); - }).toArray().join(','); - $.bc({ id: groupId, url: Role.url, method: "put", data: { type: "group", roleIds: roleIds }, title: Role.title, modal: '#dialogRole' }); + }).toArray(); + $.bc({ id: groupId, url: Role.url, method: "put", data: roleIds, query: { type: "group" }, title: Role.title, modal: '#dialogRole' }); }, '#btnSubmitUser': function (row) { var groupId = row.Id; var userIds = $dialogUser.find(':checked').map(function (index, element) { return $(element).val(); - }).toArray().join(','); - $.bc({ id: groupId, url: User.url, method: "put", data: { type: "group", userIds: userIds }, title: User.title, modal: '#dialogUser' }); + }).toArray(); + $.bc({ id: groupId, url: User.url, method: "put", data: userIds, query: { type: "group" }, title: User.title, modal: '#dialogUser' }); } } }, diff --git a/Bootstrap.Admin/wwwroot/js/longbow.common.js b/Bootstrap.Admin/wwwroot/js/longbow.common.js index 11020fb5..87a945b3 100644 --- a/Bootstrap.Admin/wwwroot/js/longbow.common.js +++ b/Bootstrap.Admin/wwwroot/js/longbow.common.js @@ -143,9 +143,16 @@ var data = options.method === 'get' ? options.data : JSON.stringify(options.data); - var url = options.id !== '' ? $.formatUrl(options.url) + '/' + options.id : $.formatUrl(options.url); + var url = options.id !== '' ? options.url + '/' + options.id : options.url; + if (options.query) { + var qs = []; + for (var key in options.query) { + qs.push($.format("{0}={1}", key, options.query[key])); + } + url = url + "?" + qs.join('&'); + } var ajaxSettings = { - url: url, + url: $.formatUrl(url), data: data, method: options.method, contentType: options.contentType, diff --git a/Bootstrap.Admin/wwwroot/js/menus.js b/Bootstrap.Admin/wwwroot/js/menus.js index 2bfbd94c..16592a31 100644 --- a/Bootstrap.Admin/wwwroot/js/menus.js +++ b/Bootstrap.Admin/wwwroot/js/menus.js @@ -42,7 +42,7 @@ events: { '#btn_assignRole': function (row) { $.bc({ - id: row.Id, url: Role.url, data: { type: "menu" }, method: "post", + id: row.Id, url: Role.url, query: { type: "menu" }, method: "post", callback: function (result) { var htmlTemplate = this.htmlTemplate; var html = $.map(result, function (element, index) { @@ -60,8 +60,8 @@ var menuId = row.Id; var roleIds = $dialogRole.find('input:checked').map(function (index, element) { return $(element).val(); - }).toArray().join(','); - $.bc({ id: menuId, url: Role.url, method: "put", data: { type: "menu", roleIds: roleIds }, title: Role.title, modal: '#dialogRole' }); + }).toArray(); + $.bc({ id: menuId, url: Role.url, method: "put", data: roleIds, query: { type: "menu" }, title: Role.title, modal: '#dialogRole' }); } }, callback: function (result) { diff --git a/Bootstrap.Admin/wwwroot/js/roles.js b/Bootstrap.Admin/wwwroot/js/roles.js index 4e706175..6f196d63 100644 --- a/Bootstrap.Admin/wwwroot/js/roles.js +++ b/Bootstrap.Admin/wwwroot/js/roles.js @@ -23,7 +23,7 @@ events: { '#btn_assignUser': function (row) { $.bc({ - id: row.Id, url: User.url, data: { type: "role" }, method: "post", + id: row.Id, url: User.url, query: { type: "role" }, method: "post", callback: function (result) { var htmlTemplate = this.htmlTemplate; var html = $.map(result, function (element, index) { @@ -39,7 +39,7 @@ }, '#btn_assignGroup': function (row) { $.bc({ - id: row.Id, url: Group.url, data: { type: "role" }, method: "post", + id: row.Id, url: Group.url, query: { type: "role" }, method: "post", callback: function (result) { var htmlTemplate = this.htmlTemplate; var html = $.map(result, function (element, index) { @@ -55,7 +55,7 @@ }, '#btn_assignMenu': function (row) { $.bc({ - id: row.Id, url: Menu.url, data: { type: "role" }, method: "post", + id: row.Id, url: Menu.url, query: { type: "role" }, method: "post", callback: function (result) { $dialogMenuHeader.text($.format('{0}-菜单授权窗口', row.RoleName)); $btnSubmitMenu.data('type', 'menu'); @@ -75,15 +75,15 @@ var roleId = row.Id; var userIds = $dialogUser.find(':checked').map(function (index, element) { return $(element).val(); - }).toArray().join(','); - $.bc({ id: roleId, url: User.url, method: "put", data: { type: "role", userIds: userIds }, modal: '#dialogUser', title: User.title }); + }).toArray(); + $.bc({ id: roleId, url: User.url, method: "put", data: userIds, query: { type: "role" }, modal: '#dialogUser', title: User.title }); }, '#btnSubmitGroup': function (row) { var roleId = row.Id; var groupIds = $dialogGroup.find(':checked').map(function (index, element) { return $(element).val(); - }).toArray().join(','); - $.bc({ id: roleId, url: Group.url, method: "put", data: { type: "role", groupIds: groupIds }, modal: '#dialogGroup', title: Group.title }); + }).toArray(); + $.bc({ id: roleId, url: Group.url, method: "put", data: groupIds, query: { type: "role" }, modal: '#dialogGroup', title: Group.title }); }, '#btnSubmitMenu': function (row) { var roleId = row.Id; diff --git a/Bootstrap.Admin/wwwroot/js/users.js b/Bootstrap.Admin/wwwroot/js/users.js index 855e5423..ba5d1637 100644 --- a/Bootstrap.Admin/wwwroot/js/users.js +++ b/Bootstrap.Admin/wwwroot/js/users.js @@ -19,7 +19,7 @@ events: { '#btn_assignRole': function (row) { $.bc({ - id: row.Id, url: Role.url, data: { type: "user" }, method: "post", + id: row.Id, url: Role.url, query: { type: "user" }, method: "post", callback: function (result) { var htmlTemplate = this.htmlTemplate; var html = $.map(result, function (element, index) { @@ -35,7 +35,7 @@ }, '#btn_assignGroup': function (row) { $.bc({ - id: row.Id, url: Group.url, data: { type: "user" }, method: "post", + id: row.Id, url: Group.url, query: { type: "user" }, method: "post", callback: function (result) { var htmlTemplate = this.htmlTemplate; var html = $.map(result, function (element, index) { @@ -53,15 +53,15 @@ var userId = row.Id; var roleIds = $dialogRole.find(':checked').map(function (index, element) { return $(element).val(); - }).toArray().join(','); - $.bc({ id: userId, url: Role.url, method: 'put', data: { type: "user", roleIds: roleIds }, title: Role.title, modal: '#dialogRole' }); + }).toArray(); + $.bc({ id: userId, url: Role.url, method: 'put', data: roleIds, query: { type: "user" }, title: Role.title, modal: '#dialogRole' }); }, '#btnSubmitGroup': function (row) { var userId = row.Id; var groupIds = $dialogGroup.find(':checked').map(function (index, element) { return $(element).val(); - }).toArray().join(','); - $.bc({ id: userId, url: Group.url, method: 'put', data: { type: "user", groupIds: groupIds }, title: Group.title, modal: '#dialogGroup' }); + }).toArray(); + $.bc({ id: userId, url: Group.url, method: 'put', data: groupIds, query: { type: "user" }, title: Group.title, modal: '#dialogGroup' }); } }, callback: function (data) { diff --git a/Bootstrap.DataAccess/CacheCleanUtility.cs b/Bootstrap.DataAccess/CacheCleanUtility.cs index 17076fb5..c663f5b8 100644 --- a/Bootstrap.DataAccess/CacheCleanUtility.cs +++ b/Bootstrap.DataAccess/CacheCleanUtility.cs @@ -1,6 +1,5 @@ using Bootstrap.Security; using Longbow.Cache; -using System; using System.Collections.Generic; using System.Linq; @@ -18,13 +17,13 @@ namespace Bootstrap.DataAccess /// /// /// - internal static void ClearCache(string roleIds = null, string userIds = null, string groupIds = null, IEnumerable menuIds = null, string dictIds = null, string cacheKey = null) + internal static void ClearCache(IEnumerable roleIds = null, IEnumerable userIds = null, IEnumerable groupIds = null, IEnumerable menuIds = null, string dictIds = null, string cacheKey = null) { var cacheKeys = new List(); var corsKeys = new List(); if (roleIds != null) { - roleIds.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).ToList().ForEach(id => + roleIds.ToList().ForEach(id => { cacheKeys.Add(string.Format("{0}-{1}", UserHelper.RetrieveUsersByRoleIdDataKey, id)); cacheKeys.Add(string.Format("{0}-{1}", GroupHelper.RetrieveGroupsByRoleIdDataKey, id)); @@ -37,7 +36,7 @@ namespace Bootstrap.DataAccess } if (userIds != null) { - userIds.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).ToList().ForEach(id => + userIds.ToList().ForEach(id => { cacheKeys.Add(string.Format("{0}-{1}", RoleHelper.RetrieveRolesByUserIdDataKey, id)); cacheKeys.Add(string.Format("{0}-{1}", GroupHelper.RetrieveGroupsByUserIdDataKey, id)); @@ -50,7 +49,7 @@ namespace Bootstrap.DataAccess } if (groupIds != null) { - groupIds.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).ToList().ForEach(id => + groupIds.ToList().ForEach(id => { cacheKeys.Add(string.Format("{0}-{1}", RoleHelper.RetrieveRolesByGroupIdDataKey, id)); cacheKeys.Add(string.Format("{0}-{1}", UserHelper.RetrieveUsersByGroupIdDataKey, id)); diff --git a/Bootstrap.DataAccess/GroupHelper.cs b/Bootstrap.DataAccess/GroupHelper.cs index 9cba9dae..cf261f13 100644 --- a/Bootstrap.DataAccess/GroupHelper.cs +++ b/Bootstrap.DataAccess/GroupHelper.cs @@ -59,7 +59,7 @@ namespace Bootstrap.DataAccess cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@ids", ids)); ret = DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd) == -1; } - CacheCleanUtility.ClearCache(groupIds: ids); + CacheCleanUtility.ClearCache(groupIds: value); return ret; } /// @@ -82,7 +82,7 @@ namespace Bootstrap.DataAccess cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@Description", DBAccessFactory.ToDBValue(p.Description))); ret = DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd) == 1; } - CacheCleanUtility.ClearCache(groupIds: p.Id == 0 ? string.Empty : p.Id.ToString()); + CacheCleanUtility.ClearCache(groupIds: p.Id == 0 ? new List() : new List() { p.Id }); return ret; } /// @@ -122,14 +122,14 @@ namespace Bootstrap.DataAccess /// /// /// - public static bool SaveGroupsByUserId(int id, string groupIds) + public static bool SaveGroupsByUserId(int id, IEnumerable groupIds) { var ret = false; DataTable dt = new DataTable(); dt.Columns.Add("UserID", typeof(int)); dt.Columns.Add("GroupID", typeof(int)); //判断用户是否选定角色 - if (!string.IsNullOrEmpty(groupIds)) groupIds.Split(',').ToList().ForEach(groupId => dt.Rows.Add(id, groupId)); + groupIds.ToList().ForEach(groupId => dt.Rows.Add(id, groupId)); using (TransactionPackage transaction = DBAccessManager.SqlDBAccess.BeginTransaction()) { try @@ -152,7 +152,7 @@ namespace Bootstrap.DataAccess transaction.CommitTransaction(); } } - CacheCleanUtility.ClearCache(groupIds: groupIds, userIds: id.ToString()); + CacheCleanUtility.ClearCache(groupIds: groupIds, userIds: new List() { id }); ret = true; } catch (Exception ex) @@ -199,13 +199,13 @@ namespace Bootstrap.DataAccess /// /// /// - public static bool SaveGroupsByRoleId(int id, string groupIds) + public static bool SaveGroupsByRoleId(int id, IEnumerable groupIds) { bool ret = false; DataTable dt = new DataTable(); dt.Columns.Add("GroupID", typeof(int)); dt.Columns.Add("RoleID", typeof(int)); - if (!string.IsNullOrEmpty(groupIds)) groupIds.Split(',').ToList().ForEach(groupId => dt.Rows.Add(groupId, id)); + groupIds.ToList().ForEach(groupId => dt.Rows.Add(groupId, id)); using (TransactionPackage transaction = DBAccessManager.SqlDBAccess.BeginTransaction()) { try @@ -227,7 +227,7 @@ namespace Bootstrap.DataAccess transaction.CommitTransaction(); } } - CacheCleanUtility.ClearCache(groupIds: groupIds, roleIds: id.ToString()); + CacheCleanUtility.ClearCache(groupIds: groupIds, roleIds: new List() { id }); ret = true; } catch (Exception ex) diff --git a/Bootstrap.DataAccess/MenuHelper.cs b/Bootstrap.DataAccess/MenuHelper.cs index f1c1874b..4f08dc74 100644 --- a/Bootstrap.DataAccess/MenuHelper.cs +++ b/Bootstrap.DataAccess/MenuHelper.cs @@ -130,7 +130,7 @@ namespace Bootstrap.DataAccess transaction.CommitTransaction(); } } - CacheCleanUtility.ClearCache(menuIds: menuIds, roleIds: id.ToString()); + CacheCleanUtility.ClearCache(menuIds: menuIds, roleIds: new List() { id }); ret = true; } catch (Exception ex) diff --git a/Bootstrap.DataAccess/RoleHelper.cs b/Bootstrap.DataAccess/RoleHelper.cs index 790b491f..a25ee79c 100644 --- a/Bootstrap.DataAccess/RoleHelper.cs +++ b/Bootstrap.DataAccess/RoleHelper.cs @@ -52,14 +52,14 @@ namespace Bootstrap.DataAccess /// /// /// - public static bool SaveRolesByUserId(int id, string roleIds) + public static bool SaveRolesByUserId(int id, IEnumerable roleIds) { var ret = false; DataTable dt = new DataTable(); dt.Columns.Add("UserID", typeof(int)); dt.Columns.Add("RoleID", typeof(int)); //判断用户是否选定角色 - if (!string.IsNullOrEmpty(roleIds)) roleIds.Split(',').ToList().ForEach(roleId => dt.Rows.Add(id, roleId)); + roleIds.ToList().ForEach(roleId => dt.Rows.Add(id, roleId)); using (TransactionPackage transaction = DBAccessManager.SqlDBAccess.BeginTransaction()) { try @@ -83,7 +83,7 @@ namespace Bootstrap.DataAccess } transaction.CommitTransaction(); } - CacheCleanUtility.ClearCache(userIds: id.ToString(), roleIds: roleIds); + CacheCleanUtility.ClearCache(userIds: new List() { id }, roleIds: roleIds); ret = true; } catch (Exception ex) @@ -136,7 +136,7 @@ namespace Bootstrap.DataAccess cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@ids", ids)); ret = DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd) == -1; } - CacheCleanUtility.ClearCache(roleIds: ids); + CacheCleanUtility.ClearCache(roleIds: value); return ret; } /// @@ -159,7 +159,7 @@ namespace Bootstrap.DataAccess cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@Description", DBAccessFactory.ToDBValue(p.Description))); ret = DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd) == 1; } - CacheCleanUtility.ClearCache(roleIds: p.Id == 0 ? string.Empty : p.Id.ToString()); + CacheCleanUtility.ClearCache(roleIds: p.Id == 0 ? new List() : new List { p.Id }); return ret; } /// @@ -193,14 +193,20 @@ namespace Bootstrap.DataAccess }, RetrieveRolesByMenuIdDataKey); return ret; } - public static bool SavaRolesByMenuId(int id, string roleIds) + /// + /// + /// + /// + /// + /// + public static bool SavaRolesByMenuId(int id, IEnumerable roleIds) { var ret = false; DataTable dt = new DataTable(); dt.Columns.Add("NavigationID", typeof(int)); dt.Columns.Add("RoleID", typeof(int)); //判断用户是否选定角色 - if (!string.IsNullOrEmpty(roleIds)) roleIds.Split(',').ToList().ForEach(roleId => dt.Rows.Add(id, roleId)); + roleIds.ToList().ForEach(roleId => dt.Rows.Add(id, roleId)); using (TransactionPackage transaction = DBAccessManager.SqlDBAccess.BeginTransaction()) { try @@ -271,14 +277,14 @@ namespace Bootstrap.DataAccess /// /// /// - public static bool SaveRolesByGroupId(int id, string roleIds) + public static bool SaveRolesByGroupId(int id, IEnumerable roleIds) { var ret = false; //构造表格 DataTable dt = new DataTable(); dt.Columns.Add("RoleID", typeof(int)); dt.Columns.Add("GroupID", typeof(int)); - if (!string.IsNullOrEmpty(roleIds)) roleIds.Split(',').ToList().ForEach(roleId => dt.Rows.Add(roleId, id)); + roleIds.ToList().ForEach(roleId => dt.Rows.Add(roleId, id)); using (TransactionPackage transaction = DBAccessManager.SqlDBAccess.BeginTransaction()) { try @@ -301,7 +307,7 @@ namespace Bootstrap.DataAccess transaction.CommitTransaction(); } } - CacheCleanUtility.ClearCache(roleIds: roleIds, groupIds: id.ToString()); + CacheCleanUtility.ClearCache(roleIds: roleIds, groupIds: new List() { id }); ret = true; } catch (Exception ex) diff --git a/Bootstrap.DataAccess/UserHelper.cs b/Bootstrap.DataAccess/UserHelper.cs index dd3dce30..99acacdf 100644 --- a/Bootstrap.DataAccess/UserHelper.cs +++ b/Bootstrap.DataAccess/UserHelper.cs @@ -94,7 +94,7 @@ namespace Bootstrap.DataAccess cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@ids", ids)); DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd); } - CacheCleanUtility.ClearCache(userIds: ids); + CacheCleanUtility.ClearCache(userIds: value); ret = true; return ret; } @@ -123,7 +123,7 @@ namespace Bootstrap.DataAccess cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@description", p.Description)); ret = DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd) == -1; } - CacheCleanUtility.ClearCache(userIds: p.Id == 0 ? string.Empty : p.Id.ToString()); + CacheCleanUtility.ClearCache(userIds: p.Id == 0 ? new List() : new List() { p.Id }); return ret; } /// @@ -142,7 +142,7 @@ namespace Bootstrap.DataAccess cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@approvedBy", approvedBy)); ret = DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd) == 1; } - CacheCleanUtility.ClearCache(userIds: id.ToString()); + CacheCleanUtility.ClearCache(userIds: new List() { id }); return ret; } /// @@ -188,7 +188,7 @@ namespace Bootstrap.DataAccess cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@rejectedReason", "未填写")); ret = DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd) == -1; } - CacheCleanUtility.ClearCache(userIds: id.ToString()); + CacheCleanUtility.ClearCache(userIds: new List() { id }); return ret; } /// @@ -227,13 +227,13 @@ namespace Bootstrap.DataAccess /// 角色ID /// 用户ID数组 /// - public static bool SaveUsersByRoleId(int id, string userIds) + public static bool SaveUsersByRoleId(int id, IEnumerable userIds) { bool ret = false; DataTable dt = new DataTable(); dt.Columns.Add("RoleID", typeof(int)); dt.Columns.Add("UserID", typeof(int)); - if (!string.IsNullOrEmpty(userIds)) userIds.Split(',').ToList().ForEach(userId => dt.Rows.Add(id, userId)); + userIds.ToList().ForEach(userId => dt.Rows.Add(id, userId)); using (TransactionPackage transaction = DBAccessManager.SqlDBAccess.BeginTransaction()) { try @@ -254,7 +254,7 @@ namespace Bootstrap.DataAccess transaction.CommitTransaction(); } } - CacheCleanUtility.ClearCache(userIds: userIds, roleIds: id.ToString()); + CacheCleanUtility.ClearCache(userIds: userIds, roleIds: new List() { id }); ret = true; } catch (Exception ex) @@ -301,13 +301,13 @@ namespace Bootstrap.DataAccess /// GroupID /// 用户ID数组 /// - public static bool SaveUsersByGroupId(int id, string userIds) + public static bool SaveUsersByGroupId(int id, IEnumerable userIds) { bool ret = false; DataTable dt = new DataTable(); dt.Columns.Add("UserID", typeof(int)); dt.Columns.Add("GroupID", typeof(int)); - if (!string.IsNullOrEmpty(userIds)) userIds.Split(',').ToList().ForEach(userId => dt.Rows.Add(userId, id)); + userIds.ToList().ForEach(userId => dt.Rows.Add(userId, id)); using (TransactionPackage transaction = DBAccessManager.SqlDBAccess.BeginTransaction()) { try @@ -328,7 +328,7 @@ namespace Bootstrap.DataAccess transaction.CommitTransaction(); } } - CacheCleanUtility.ClearCache(userIds: userIds, groupIds: id.ToString()); + CacheCleanUtility.ClearCache(userIds: userIds, groupIds: new List() { id }); ret = true; } catch (Exception ex)