重构代码:移除JObject参数使用[FromQuery]string type

This commit is contained in:
Argo-MacBookPro 2018-09-13 19:21:35 +08:00
parent 8dd846824c
commit 3e74b7bf07
15 changed files with 174 additions and 172 deletions

View File

@ -2,7 +2,6 @@
using Bootstrap.DataAccess; using Bootstrap.DataAccess;
using Longbow.Web.Mvc; using Longbow.Web.Mvc;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json.Linq;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
@ -56,14 +55,13 @@ namespace Bootstrap.Admin.Controllers.Api
/// ///
/// </summary> /// </summary>
/// <param name="id"></param> /// <param name="id"></param>
/// <param name="value"></param> /// <param name="type"></param>
/// <returns></returns> /// <returns></returns>
[HttpPost("{id}")] [HttpPost("{id}")]
public IEnumerable<Group> Post(int id, [FromBody]JObject value) public IEnumerable<Group> Post(int id, [FromQuery]string type)
{ {
var ret = new List<Group>(); var ret = new List<Group>();
dynamic json = value; switch (type)
switch ((string)json.type)
{ {
case "user": case "user":
ret = GroupHelper.RetrieveGroupsByUserId(id).ToList(); ret = GroupHelper.RetrieveGroupsByUserId(id).ToList();
@ -80,15 +78,14 @@ namespace Bootstrap.Admin.Controllers.Api
/// ///
/// </summary> /// </summary>
/// <param name="id"></param> /// <param name="id"></param>
/// <param name="value"></param> /// <param name="groupIds"></param>
/// <param name="type"></param>
/// <returns></returns> /// <returns></returns>
[HttpPut("{id}")] [HttpPut("{id}")]
public bool Put(int id, [FromBody]JObject value) public bool Put(int id, [FromBody]IEnumerable<int> groupIds, [FromQuery]string type)
{ {
var ret = false; var ret = false;
dynamic json = value; switch (type)
string groupIds = json.groupIds;
switch ((string)json.type)
{ {
case "user": case "user":
ret = GroupHelper.SaveGroupsByUserId(id, groupIds); ret = GroupHelper.SaveGroupsByUserId(id, groupIds);

View File

@ -3,7 +3,6 @@ using Bootstrap.DataAccess;
using Bootstrap.Security; using Bootstrap.Security;
using Longbow.Web.Mvc; using Longbow.Web.Mvc;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json.Linq;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
@ -50,11 +49,10 @@ namespace Bootstrap.Admin.Controllers.Api
/// <param name="value"></param> /// <param name="value"></param>
/// <returns></returns> /// <returns></returns>
[HttpPost("{id}")] [HttpPost("{id}")]
public IEnumerable<BootstrapMenu> Post(int id, [FromBody]JObject value) public IEnumerable<BootstrapMenu> Post(int id, [FromQuery]string type)
{ {
var ret = new List<BootstrapMenu>(); var ret = new List<BootstrapMenu>();
dynamic json = value; switch (type)
switch ((string)json.type)
{ {
case "role": case "role":
ret = MenuHelper.RetrieveMenusByRoleId(id).ToList(); ret = MenuHelper.RetrieveMenusByRoleId(id).ToList();

View File

@ -25,19 +25,17 @@ namespace Bootstrap.Admin.Controllers.Api
{ {
return value.RetrieveData(); return value.RetrieveData();
} }
/// <summary> /// <summary>
/// /// 通过指定ID获得所有角色集合
/// </summary> /// </summary>
/// <param name="id"></param> /// <param name="id">用户ID/部门ID/菜单ID</param>
/// <param name="value"></param> /// <param name="type">类型</param>
/// <returns></returns> /// <returns></returns>
[HttpPost("{id}")] [HttpPost("{id}")]
public IEnumerable<Role> Post(int id, [FromBody]JObject value) public IEnumerable<Role> Post(int id, [FromQuery]string type)
{ {
var ret = new List<Role>(); var ret = new List<Role>();
dynamic json = value; switch (type)
switch ((string)json.type)
{ {
case "user": case "user":
ret = RoleHelper.RetrieveRolesByUserId(id).ToList(); ret = RoleHelper.RetrieveRolesByUserId(id).ToList();
@ -53,18 +51,18 @@ namespace Bootstrap.Admin.Controllers.Api
} }
return ret; return ret;
} }
/// <summary>
/// <summary>根据GroupID获取 /// 根据GroupID获取
/// </summary> /// </summary>
/// <param name="value"></param> /// <param name="id"></param>
/// <param name="roleIds"></param>
/// <param name="type"></param>
/// <returns></returns> /// <returns></returns>
[HttpPut("{id}")] [HttpPut("{id}")]
public bool Put(int id, [FromBody]JObject value) public bool Put(int id, [FromBody]IEnumerable<int> roleIds, [FromQuery]string type)
{ {
var ret = false; var ret = false;
dynamic json = value; switch (type)
string roleIds = json.roleIds;
switch ((string)json.type)
{ {
case "user": case "user":
ret = RoleHelper.SaveRolesByUserId(id, roleIds); ret = RoleHelper.SaveRolesByUserId(id, roleIds);

View File

@ -3,7 +3,6 @@ using Bootstrap.DataAccess;
using Longbow.Web.Mvc; using Longbow.Web.Mvc;
using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json.Linq;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
@ -53,14 +52,13 @@ namespace Bootstrap.Admin.Controllers.Api
/// ///
/// </summary> /// </summary>
/// <param name="id"></param> /// <param name="id"></param>
/// <param name="value"></param> /// <param name="type"></param>
/// <returns></returns> /// <returns></returns>
[HttpPost("{id}")] [HttpPost("{id}")]
public IEnumerable<User> Post(int id, [FromBody]JObject value) public IEnumerable<User> Post(int id, [FromQuery]string type)
{ {
var ret = new List<User>(); var ret = new List<User>();
dynamic json = value; switch (type)
switch ((string)json.type)
{ {
case "role": case "role":
ret = UserHelper.RetrieveUsersByRoleId(id).ToList(); ret = UserHelper.RetrieveUsersByRoleId(id).ToList();
@ -89,15 +87,14 @@ namespace Bootstrap.Admin.Controllers.Api
/// ///
/// </summary> /// </summary>
/// <param name="id"></param> /// <param name="id"></param>
/// <param name="value"></param> /// <param name="userIds"></param>
/// <param name="type"></param>
/// <returns></returns> /// <returns></returns>
[HttpPut("{id}")] [HttpPut("{id}")]
public bool Put(int id, [FromBody]JObject value) public bool Put(int id, [FromBody]IEnumerable<int> userIds, [FromQuery]string type)
{ {
var ret = false; var ret = false;
dynamic json = value; switch (type)
string userIds = json.userIds;
switch ((string)json.type)
{ {
case "role": case "role":
ret = UserHelper.SaveUsersByRoleId(id, userIds); ret = UserHelper.SaveUsersByRoleId(id, userIds);

View File

@ -40,7 +40,7 @@
nestMenu: function (callback) { nestMenu: function (callback) {
var $this = $(this); var $this = $(this);
$.bc({ $.bc({
id: 0, url: Menu.url, data: { type: "user" }, method: "post", id: 0, url: Menu.url, query: { type: "user" }, method: "post",
callback: function (result) { callback: function (result) {
var html = ""; var html = "";
if ($.isArray(result)) html = cascadeMenu(result); if ($.isArray(result)) html = cascadeMenu(result);

View File

@ -17,7 +17,7 @@
events: { events: {
'#btn_assignRole': function (row) { '#btn_assignRole': function (row) {
$.bc({ $.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) { callback: function (result) {
var htmlTemplate = this.htmlTemplate; var htmlTemplate = this.htmlTemplate;
var html = $.map(result, function (element, index) { var html = $.map(result, function (element, index) {
@ -33,7 +33,7 @@
}, },
'#btn_assignUser': function (row) { '#btn_assignUser': function (row) {
$.bc({ $.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) { callback: function (result) {
var htmlTemplate = this.htmlTemplate; var htmlTemplate = this.htmlTemplate;
var html = $.map(result, function (element, index) { var html = $.map(result, function (element, index) {
@ -51,15 +51,15 @@
var groupId = row.Id; var groupId = row.Id;
var roleIds = $dialogRole.find('input:checked').map(function (index, element) { var roleIds = $dialogRole.find('input:checked').map(function (index, element) {
return $(element).val(); return $(element).val();
}).toArray().join(','); }).toArray();
$.bc({ id: groupId, url: Role.url, method: "put", data: { type: "group", roleIds: roleIds }, title: Role.title, modal: '#dialogRole' }); $.bc({ id: groupId, url: Role.url, method: "put", data: roleIds, query: { type: "group" }, title: Role.title, modal: '#dialogRole' });
}, },
'#btnSubmitUser': function (row) { '#btnSubmitUser': function (row) {
var groupId = row.Id; var groupId = row.Id;
var userIds = $dialogUser.find(':checked').map(function (index, element) { var userIds = $dialogUser.find(':checked').map(function (index, element) {
return $(element).val(); return $(element).val();
}).toArray().join(','); }).toArray();
$.bc({ id: groupId, url: User.url, method: "put", data: { type: "group", userIds: userIds }, title: User.title, modal: '#dialogUser' }); $.bc({ id: groupId, url: User.url, method: "put", data: userIds, query: { type: "group" }, title: User.title, modal: '#dialogUser' });
} }
} }
}, },

View File

@ -143,9 +143,16 @@
var data = options.method === 'get' ? options.data : JSON.stringify(options.data); 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 = { var ajaxSettings = {
url: url, url: $.formatUrl(url),
data: data, data: data,
method: options.method, method: options.method,
contentType: options.contentType, contentType: options.contentType,

View File

@ -42,7 +42,7 @@
events: { events: {
'#btn_assignRole': function (row) { '#btn_assignRole': function (row) {
$.bc({ $.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) { callback: function (result) {
var htmlTemplate = this.htmlTemplate; var htmlTemplate = this.htmlTemplate;
var html = $.map(result, function (element, index) { var html = $.map(result, function (element, index) {
@ -60,8 +60,8 @@
var menuId = row.Id; var menuId = row.Id;
var roleIds = $dialogRole.find('input:checked').map(function (index, element) { var roleIds = $dialogRole.find('input:checked').map(function (index, element) {
return $(element).val(); return $(element).val();
}).toArray().join(','); }).toArray();
$.bc({ id: menuId, url: Role.url, method: "put", data: { type: "menu", roleIds: roleIds }, title: Role.title, modal: '#dialogRole' }); $.bc({ id: menuId, url: Role.url, method: "put", data: roleIds, query: { type: "menu" }, title: Role.title, modal: '#dialogRole' });
} }
}, },
callback: function (result) { callback: function (result) {

View File

@ -23,7 +23,7 @@
events: { events: {
'#btn_assignUser': function (row) { '#btn_assignUser': function (row) {
$.bc({ $.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) { callback: function (result) {
var htmlTemplate = this.htmlTemplate; var htmlTemplate = this.htmlTemplate;
var html = $.map(result, function (element, index) { var html = $.map(result, function (element, index) {
@ -39,7 +39,7 @@
}, },
'#btn_assignGroup': function (row) { '#btn_assignGroup': function (row) {
$.bc({ $.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) { callback: function (result) {
var htmlTemplate = this.htmlTemplate; var htmlTemplate = this.htmlTemplate;
var html = $.map(result, function (element, index) { var html = $.map(result, function (element, index) {
@ -55,7 +55,7 @@
}, },
'#btn_assignMenu': function (row) { '#btn_assignMenu': function (row) {
$.bc({ $.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) { callback: function (result) {
$dialogMenuHeader.text($.format('{0}-菜单授权窗口', row.RoleName)); $dialogMenuHeader.text($.format('{0}-菜单授权窗口', row.RoleName));
$btnSubmitMenu.data('type', 'menu'); $btnSubmitMenu.data('type', 'menu');
@ -75,15 +75,15 @@
var roleId = row.Id; var roleId = row.Id;
var userIds = $dialogUser.find(':checked').map(function (index, element) { var userIds = $dialogUser.find(':checked').map(function (index, element) {
return $(element).val(); return $(element).val();
}).toArray().join(','); }).toArray();
$.bc({ id: roleId, url: User.url, method: "put", data: { type: "role", userIds: userIds }, modal: '#dialogUser', title: User.title }); $.bc({ id: roleId, url: User.url, method: "put", data: userIds, query: { type: "role" }, modal: '#dialogUser', title: User.title });
}, },
'#btnSubmitGroup': function (row) { '#btnSubmitGroup': function (row) {
var roleId = row.Id; var roleId = row.Id;
var groupIds = $dialogGroup.find(':checked').map(function (index, element) { var groupIds = $dialogGroup.find(':checked').map(function (index, element) {
return $(element).val(); return $(element).val();
}).toArray().join(','); }).toArray();
$.bc({ id: roleId, url: Group.url, method: "put", data: { type: "role", groupIds: groupIds }, modal: '#dialogGroup', title: Group.title }); $.bc({ id: roleId, url: Group.url, method: "put", data: groupIds, query: { type: "role" }, modal: '#dialogGroup', title: Group.title });
}, },
'#btnSubmitMenu': function (row) { '#btnSubmitMenu': function (row) {
var roleId = row.Id; var roleId = row.Id;

View File

@ -19,7 +19,7 @@
events: { events: {
'#btn_assignRole': function (row) { '#btn_assignRole': function (row) {
$.bc({ $.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) { callback: function (result) {
var htmlTemplate = this.htmlTemplate; var htmlTemplate = this.htmlTemplate;
var html = $.map(result, function (element, index) { var html = $.map(result, function (element, index) {
@ -35,7 +35,7 @@
}, },
'#btn_assignGroup': function (row) { '#btn_assignGroup': function (row) {
$.bc({ $.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) { callback: function (result) {
var htmlTemplate = this.htmlTemplate; var htmlTemplate = this.htmlTemplate;
var html = $.map(result, function (element, index) { var html = $.map(result, function (element, index) {
@ -53,15 +53,15 @@
var userId = row.Id; var userId = row.Id;
var roleIds = $dialogRole.find(':checked').map(function (index, element) { var roleIds = $dialogRole.find(':checked').map(function (index, element) {
return $(element).val(); return $(element).val();
}).toArray().join(','); }).toArray();
$.bc({ id: userId, url: Role.url, method: 'put', data: { type: "user", roleIds: roleIds }, title: Role.title, modal: '#dialogRole' }); $.bc({ id: userId, url: Role.url, method: 'put', data: roleIds, query: { type: "user" }, title: Role.title, modal: '#dialogRole' });
}, },
'#btnSubmitGroup': function (row) { '#btnSubmitGroup': function (row) {
var userId = row.Id; var userId = row.Id;
var groupIds = $dialogGroup.find(':checked').map(function (index, element) { var groupIds = $dialogGroup.find(':checked').map(function (index, element) {
return $(element).val(); return $(element).val();
}).toArray().join(','); }).toArray();
$.bc({ id: userId, url: Group.url, method: 'put', data: { type: "user", groupIds: groupIds }, title: Group.title, modal: '#dialogGroup' }); $.bc({ id: userId, url: Group.url, method: 'put', data: groupIds, query: { type: "user" }, title: Group.title, modal: '#dialogGroup' });
} }
}, },
callback: function (data) { callback: function (data) {

View File

@ -1,6 +1,5 @@
using Bootstrap.Security; using Bootstrap.Security;
using Longbow.Cache; using Longbow.Cache;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
@ -18,13 +17,13 @@ namespace Bootstrap.DataAccess
/// <param name="menuIds"></param> /// <param name="menuIds"></param>
/// <param name="dictIds"></param> /// <param name="dictIds"></param>
/// <param name="cacheKey"></param> /// <param name="cacheKey"></param>
internal static void ClearCache(string roleIds = null, string userIds = null, string groupIds = null, IEnumerable<int> menuIds = null, string dictIds = null, string cacheKey = null) internal static void ClearCache(IEnumerable<int> roleIds = null, IEnumerable<int> userIds = null, IEnumerable<int> groupIds = null, IEnumerable<int> menuIds = null, string dictIds = null, string cacheKey = null)
{ {
var cacheKeys = new List<string>(); var cacheKeys = new List<string>();
var corsKeys = new List<string>(); var corsKeys = new List<string>();
if (roleIds != null) 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}", UserHelper.RetrieveUsersByRoleIdDataKey, id));
cacheKeys.Add(string.Format("{0}-{1}", GroupHelper.RetrieveGroupsByRoleIdDataKey, id)); cacheKeys.Add(string.Format("{0}-{1}", GroupHelper.RetrieveGroupsByRoleIdDataKey, id));
@ -37,7 +36,7 @@ namespace Bootstrap.DataAccess
} }
if (userIds != null) 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}", RoleHelper.RetrieveRolesByUserIdDataKey, id));
cacheKeys.Add(string.Format("{0}-{1}", GroupHelper.RetrieveGroupsByUserIdDataKey, id)); cacheKeys.Add(string.Format("{0}-{1}", GroupHelper.RetrieveGroupsByUserIdDataKey, id));
@ -50,7 +49,7 @@ namespace Bootstrap.DataAccess
} }
if (groupIds != null) 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}", RoleHelper.RetrieveRolesByGroupIdDataKey, id));
cacheKeys.Add(string.Format("{0}-{1}", UserHelper.RetrieveUsersByGroupIdDataKey, id)); cacheKeys.Add(string.Format("{0}-{1}", UserHelper.RetrieveUsersByGroupIdDataKey, id));

View File

@ -59,7 +59,7 @@ namespace Bootstrap.DataAccess
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@ids", ids)); cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@ids", ids));
ret = DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd) == -1; ret = DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd) == -1;
} }
CacheCleanUtility.ClearCache(groupIds: ids); CacheCleanUtility.ClearCache(groupIds: value);
return ret; return ret;
} }
/// <summary> /// <summary>
@ -82,7 +82,7 @@ namespace Bootstrap.DataAccess
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@Description", DBAccessFactory.ToDBValue(p.Description))); cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@Description", DBAccessFactory.ToDBValue(p.Description)));
ret = DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd) == 1; 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<int>() : new List<int>() { p.Id });
return ret; return ret;
} }
/// <summary> /// <summary>
@ -122,14 +122,14 @@ namespace Bootstrap.DataAccess
/// <param name="id"></param> /// <param name="id"></param>
/// <param name="groupIds"></param> /// <param name="groupIds"></param>
/// <returns></returns> /// <returns></returns>
public static bool SaveGroupsByUserId(int id, string groupIds) public static bool SaveGroupsByUserId(int id, IEnumerable<int> groupIds)
{ {
var ret = false; var ret = false;
DataTable dt = new DataTable(); DataTable dt = new DataTable();
dt.Columns.Add("UserID", typeof(int)); dt.Columns.Add("UserID", typeof(int));
dt.Columns.Add("GroupID", 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()) using (TransactionPackage transaction = DBAccessManager.SqlDBAccess.BeginTransaction())
{ {
try try
@ -152,7 +152,7 @@ namespace Bootstrap.DataAccess
transaction.CommitTransaction(); transaction.CommitTransaction();
} }
} }
CacheCleanUtility.ClearCache(groupIds: groupIds, userIds: id.ToString()); CacheCleanUtility.ClearCache(groupIds: groupIds, userIds: new List<int>() { id });
ret = true; ret = true;
} }
catch (Exception ex) catch (Exception ex)
@ -199,13 +199,13 @@ namespace Bootstrap.DataAccess
/// <param name="id"></param> /// <param name="id"></param>
/// <param name="groupIds"></param> /// <param name="groupIds"></param>
/// <returns></returns> /// <returns></returns>
public static bool SaveGroupsByRoleId(int id, string groupIds) public static bool SaveGroupsByRoleId(int id, IEnumerable<int> groupIds)
{ {
bool ret = false; bool ret = false;
DataTable dt = new DataTable(); DataTable dt = new DataTable();
dt.Columns.Add("GroupID", typeof(int)); dt.Columns.Add("GroupID", typeof(int));
dt.Columns.Add("RoleID", 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()) using (TransactionPackage transaction = DBAccessManager.SqlDBAccess.BeginTransaction())
{ {
try try
@ -227,7 +227,7 @@ namespace Bootstrap.DataAccess
transaction.CommitTransaction(); transaction.CommitTransaction();
} }
} }
CacheCleanUtility.ClearCache(groupIds: groupIds, roleIds: id.ToString()); CacheCleanUtility.ClearCache(groupIds: groupIds, roleIds: new List<int>() { id });
ret = true; ret = true;
} }
catch (Exception ex) catch (Exception ex)

View File

@ -130,7 +130,7 @@ namespace Bootstrap.DataAccess
transaction.CommitTransaction(); transaction.CommitTransaction();
} }
} }
CacheCleanUtility.ClearCache(menuIds: menuIds, roleIds: id.ToString()); CacheCleanUtility.ClearCache(menuIds: menuIds, roleIds: new List<int>() { id });
ret = true; ret = true;
} }
catch (Exception ex) catch (Exception ex)

View File

@ -52,14 +52,14 @@ namespace Bootstrap.DataAccess
/// <param name="id"></param> /// <param name="id"></param>
/// <param name="roleIds"></param> /// <param name="roleIds"></param>
/// <returns></returns> /// <returns></returns>
public static bool SaveRolesByUserId(int id, string roleIds) public static bool SaveRolesByUserId(int id, IEnumerable<int> roleIds)
{ {
var ret = false; var ret = false;
DataTable dt = new DataTable(); DataTable dt = new DataTable();
dt.Columns.Add("UserID", typeof(int)); dt.Columns.Add("UserID", typeof(int));
dt.Columns.Add("RoleID", 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()) using (TransactionPackage transaction = DBAccessManager.SqlDBAccess.BeginTransaction())
{ {
try try
@ -83,7 +83,7 @@ namespace Bootstrap.DataAccess
} }
transaction.CommitTransaction(); transaction.CommitTransaction();
} }
CacheCleanUtility.ClearCache(userIds: id.ToString(), roleIds: roleIds); CacheCleanUtility.ClearCache(userIds: new List<int>() { id }, roleIds: roleIds);
ret = true; ret = true;
} }
catch (Exception ex) catch (Exception ex)
@ -136,7 +136,7 @@ namespace Bootstrap.DataAccess
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@ids", ids)); cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@ids", ids));
ret = DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd) == -1; ret = DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd) == -1;
} }
CacheCleanUtility.ClearCache(roleIds: ids); CacheCleanUtility.ClearCache(roleIds: value);
return ret; return ret;
} }
/// <summary> /// <summary>
@ -159,7 +159,7 @@ namespace Bootstrap.DataAccess
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@Description", DBAccessFactory.ToDBValue(p.Description))); cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@Description", DBAccessFactory.ToDBValue(p.Description)));
ret = DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd) == 1; 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<int>() : new List<int> { p.Id });
return ret; return ret;
} }
/// <summary> /// <summary>
@ -193,14 +193,20 @@ namespace Bootstrap.DataAccess
}, RetrieveRolesByMenuIdDataKey); }, RetrieveRolesByMenuIdDataKey);
return ret; return ret;
} }
public static bool SavaRolesByMenuId(int id, string roleIds) /// <summary>
///
/// </summary>
/// <param name="id"></param>
/// <param name="roleIds"></param>
/// <returns></returns>
public static bool SavaRolesByMenuId(int id, IEnumerable<int> roleIds)
{ {
var ret = false; var ret = false;
DataTable dt = new DataTable(); DataTable dt = new DataTable();
dt.Columns.Add("NavigationID", typeof(int)); dt.Columns.Add("NavigationID", typeof(int));
dt.Columns.Add("RoleID", 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()) using (TransactionPackage transaction = DBAccessManager.SqlDBAccess.BeginTransaction())
{ {
try try
@ -271,14 +277,14 @@ namespace Bootstrap.DataAccess
/// <param name="id"></param> /// <param name="id"></param>
/// <param name="roleIds"></param> /// <param name="roleIds"></param>
/// <returns></returns> /// <returns></returns>
public static bool SaveRolesByGroupId(int id, string roleIds) public static bool SaveRolesByGroupId(int id, IEnumerable<int> roleIds)
{ {
var ret = false; var ret = false;
//构造表格 //构造表格
DataTable dt = new DataTable(); DataTable dt = new DataTable();
dt.Columns.Add("RoleID", typeof(int)); dt.Columns.Add("RoleID", typeof(int));
dt.Columns.Add("GroupID", 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()) using (TransactionPackage transaction = DBAccessManager.SqlDBAccess.BeginTransaction())
{ {
try try
@ -301,7 +307,7 @@ namespace Bootstrap.DataAccess
transaction.CommitTransaction(); transaction.CommitTransaction();
} }
} }
CacheCleanUtility.ClearCache(roleIds: roleIds, groupIds: id.ToString()); CacheCleanUtility.ClearCache(roleIds: roleIds, groupIds: new List<int>() { id });
ret = true; ret = true;
} }
catch (Exception ex) catch (Exception ex)

View File

@ -94,7 +94,7 @@ namespace Bootstrap.DataAccess
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@ids", ids)); cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@ids", ids));
DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd); DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd);
} }
CacheCleanUtility.ClearCache(userIds: ids); CacheCleanUtility.ClearCache(userIds: value);
ret = true; ret = true;
return ret; return ret;
} }
@ -123,7 +123,7 @@ namespace Bootstrap.DataAccess
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@description", p.Description)); cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@description", p.Description));
ret = DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd) == -1; 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<int>() : new List<int>() { p.Id });
return ret; return ret;
} }
/// <summary> /// <summary>
@ -142,7 +142,7 @@ namespace Bootstrap.DataAccess
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@approvedBy", approvedBy)); cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@approvedBy", approvedBy));
ret = DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd) == 1; ret = DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd) == 1;
} }
CacheCleanUtility.ClearCache(userIds: id.ToString()); CacheCleanUtility.ClearCache(userIds: new List<int>() { id });
return ret; return ret;
} }
/// <summary> /// <summary>
@ -188,7 +188,7 @@ namespace Bootstrap.DataAccess
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@rejectedReason", "未填写")); cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@rejectedReason", "未填写"));
ret = DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd) == -1; ret = DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd) == -1;
} }
CacheCleanUtility.ClearCache(userIds: id.ToString()); CacheCleanUtility.ClearCache(userIds: new List<int>() { id });
return ret; return ret;
} }
/// <summary> /// <summary>
@ -227,13 +227,13 @@ namespace Bootstrap.DataAccess
/// <param name="id">角色ID</param> /// <param name="id">角色ID</param>
/// <param name="userIds">用户ID数组</param> /// <param name="userIds">用户ID数组</param>
/// <returns></returns> /// <returns></returns>
public static bool SaveUsersByRoleId(int id, string userIds) public static bool SaveUsersByRoleId(int id, IEnumerable<int> userIds)
{ {
bool ret = false; bool ret = false;
DataTable dt = new DataTable(); DataTable dt = new DataTable();
dt.Columns.Add("RoleID", typeof(int)); dt.Columns.Add("RoleID", typeof(int));
dt.Columns.Add("UserID", 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()) using (TransactionPackage transaction = DBAccessManager.SqlDBAccess.BeginTransaction())
{ {
try try
@ -254,7 +254,7 @@ namespace Bootstrap.DataAccess
transaction.CommitTransaction(); transaction.CommitTransaction();
} }
} }
CacheCleanUtility.ClearCache(userIds: userIds, roleIds: id.ToString()); CacheCleanUtility.ClearCache(userIds: userIds, roleIds: new List<int>() { id });
ret = true; ret = true;
} }
catch (Exception ex) catch (Exception ex)
@ -301,13 +301,13 @@ namespace Bootstrap.DataAccess
/// <param name="id">GroupID</param> /// <param name="id">GroupID</param>
/// <param name="userIds">用户ID数组</param> /// <param name="userIds">用户ID数组</param>
/// <returns></returns> /// <returns></returns>
public static bool SaveUsersByGroupId(int id, string userIds) public static bool SaveUsersByGroupId(int id, IEnumerable<int> userIds)
{ {
bool ret = false; bool ret = false;
DataTable dt = new DataTable(); DataTable dt = new DataTable();
dt.Columns.Add("UserID", typeof(int)); dt.Columns.Add("UserID", typeof(int));
dt.Columns.Add("GroupID", 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()) using (TransactionPackage transaction = DBAccessManager.SqlDBAccess.BeginTransaction())
{ {
try try
@ -328,7 +328,7 @@ namespace Bootstrap.DataAccess
transaction.CommitTransaction(); transaction.CommitTransaction();
} }
} }
CacheCleanUtility.ClearCache(userIds: userIds, groupIds: id.ToString()); CacheCleanUtility.ClearCache(userIds: userIds, groupIds: new List<int>() { id });
ret = true; ret = true;
} }
catch (Exception ex) catch (Exception ex)