diff --git a/Bootstrap.Admin/Scripts/Groups.js b/Bootstrap.Admin/Scripts/Groups.js
index cf2b7829..fc2fdaf3 100644
--- a/Bootstrap.Admin/Scripts/Groups.js
+++ b/Bootstrap.Admin/Scripts/Groups.js
@@ -22,7 +22,7 @@
id: 'btn_assignUser',
click: function (row) {
User.getUsersByGroupeId(row.ID, function (data) {
- $("#dialogUser .modal-title").text($.format('{0}-指定用户窗口', row.GroupName));
+ $("#dialogUser .modal-title").text($.format('{0}-用户授权窗口', row.GroupName));
$('#dialogUser form').html(data);
$('#dialogUser').modal('show');
});
diff --git a/Bootstrap.Admin/Scripts/Roles.js b/Bootstrap.Admin/Scripts/Roles.js
index b6b26150..2c152f82 100644
--- a/Bootstrap.Admin/Scripts/Roles.js
+++ b/Bootstrap.Admin/Scripts/Roles.js
@@ -13,7 +13,7 @@
id: 'btn_assignUser',
click: function (row) {
User.getUsersByRoleId(row.ID, function (data) {
- $("#dialogUser.modal-title").text($.format('{0}-用户授权窗口', row.RoleName));
+ $("#dialogUser .modal-title").text($.format('{0}-用户授权窗口', row.RoleName));
$('#dialogUser form').html(data);
$('#dialogUser').modal('show');
})
@@ -22,7 +22,7 @@
id: 'btn_assignGroup',
click: function (row) {
Group.getGroupsByRoleId(row.ID, function (data) {
- $("#dialogGroup.modal-title").text($.format('{0}-部门授权窗口', row.RoleName));
+ $("#dialogGroup .modal-title").text($.format('{0}-部门授权窗口', row.RoleName));
$('#dialogGroup form').html(data);
$('#dialogGroup').modal('show');
})
diff --git a/Bootstrap.Admin/Web.config b/Bootstrap.Admin/Web.config
index b33e2b92..caaccac3 100644
--- a/Bootstrap.Admin/Web.config
+++ b/Bootstrap.Admin/Web.config
@@ -36,6 +36,7 @@
+
diff --git a/Bootstrap.DataAccess/GroupHelper.cs b/Bootstrap.DataAccess/GroupHelper.cs
index 53b8acd6..02fa034e 100644
--- a/Bootstrap.DataAccess/GroupHelper.cs
+++ b/Bootstrap.DataAccess/GroupHelper.cs
@@ -20,7 +20,7 @@ namespace Bootstrap.DataAccess
{
private const string GroupDataKey = "GroupData-CodeGroupHelper";
private const string GroupUserIDDataKey = "GroupData-CodeGroupHelper-";
- private const string GroupRoleIDDataKey = "GroupData-CodeGroupHelper-Role-";
+ private const string GroupRoleIDDataKey = "GroupData-CodeGroupHelper-Role-";
///
/// 查询所有群组信息
///
@@ -150,63 +150,60 @@ namespace Bootstrap.DataAccess
///
///
///
- public static bool SaveGroupsByUserId(int id, string value)
+ public static bool SaveGroupsByUserId(int id, string groupIds)
{
+ var ret = false;
DataTable dt = new DataTable();
dt.Columns.Add("UserID", typeof(int));
dt.Columns.Add("GroupID", typeof(int));
//判断用户是否选定角色
- if (!string.IsNullOrEmpty(value))
+ if (!string.IsNullOrEmpty(groupIds))
{
- string[] groupIDs = value.Split(',');
- foreach (string groupID in groupIDs)
+ groupIds.Split(',').ToList().ForEach(groupId =>
{
DataRow row = dt.NewRow();
- row["UserID"] = id;
- row["GroupID"] = groupID;
- dt.Rows.Add(row);
- }
+ dt.Rows.Add(id, groupId);
+ });
}
-
- string sql = "delete from UserGroup where UserID=@UserID;";
- using (DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql))
+ using (TransactionPackage transaction = DBAccessManager.SqlDBAccess.BeginTransaction())
{
- cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@UserID", id, ParameterDirection.Input));
- using (TransactionPackage transaction = DBAccessManager.SqlDBAccess.BeginTransaction())
+ try
{
- using (SqlBulkCopy bulk = new SqlBulkCopy((SqlConnection)transaction.Transaction.Connection, SqlBulkCopyOptions.Default, (SqlTransaction)transaction.Transaction))
+ //删除用户部门表中该用户所有的部门关系
+ string sql = "delete from UserGroup where UserID=@UserID;";
+ using (DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql))
{
- bulk.BatchSize = 1000;
- bulk.DestinationTableName = "UserGroup";
- bulk.ColumnMappings.Add("UserID", "UserID");
- bulk.ColumnMappings.Add("GroupID", "GroupID");
+ cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@UserID", id, ParameterDirection.Input));
+ DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd, transaction);
- bool ret = true;
- try
+ // insert batch data into config table
+ using (SqlBulkCopy bulk = new SqlBulkCopy((SqlConnection)transaction.Transaction.Connection, SqlBulkCopyOptions.Default, (SqlTransaction)transaction.Transaction))
{
- DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd, transaction);
+ bulk.BatchSize = 1000;
+ bulk.DestinationTableName = "UserGroup";
+ bulk.ColumnMappings.Add("UserID", "UserID");
+ bulk.ColumnMappings.Add("GroupID", "GroupID");
bulk.WriteToServer(dt);
transaction.CommitTransaction();
- ClearCache();
}
- catch (Exception ex)
- {
- ret = false;
- transaction.RollbackTransaction();
- }
- return ret;
}
+ ret = true;
+ ClearCache();
+ }
+ catch (Exception ex)
+ {
+ ExceptionManager.Publish(ex);
+ transaction.RollbackTransaction();
}
}
+ return ret;
}
// 更新缓存
- private static void ClearCache()
+ private static void ClearCache(string cacheKey = null)
{
- CacheManager.Clear(key => key == GroupDataKey);
- CacheManager.Clear(key => key == GroupUserIDDataKey);
- CacheManager.Clear(key => key.Contains(GroupRoleIDDataKey));
+ CacheManager.Clear(key => string.IsNullOrEmpty(cacheKey) || key == cacheKey);
}
- ///
+ ///
/// 根据角色ID指派部门
///
///
@@ -228,9 +225,9 @@ namespace Bootstrap.DataAccess
{
Groups.Add(new Group()
{
- ID=(int)reader[0],
- GroupName=(string)reader[1],
- Description=(string)reader[2],
+ ID = (int)reader[0],
+ GroupName = (string)reader[1],
+ Description = (string)reader[2],
Checked = (string)reader[3]
});
}
@@ -238,7 +235,7 @@ namespace Bootstrap.DataAccess
}
catch (Exception ex) { ExceptionManager.Publish(ex); }
return Groups;
- },CacheSection.RetrieveDescByKey(GroupRoleIDDataKey));
+ }, CacheSection.RetrieveDescByKey(GroupRoleIDDataKey));
}
///
/// 根据角色ID以及选定的部门ID,保到角色部门表
@@ -260,21 +257,22 @@ namespace Bootstrap.DataAccess
dt.Rows.Add(groupId, id);
});
}
- using(TransactionPackage transaction=DBAccessManager.SqlDBAccess.BeginTransaction()){
+ using (TransactionPackage transaction = DBAccessManager.SqlDBAccess.BeginTransaction())
+ {
try
{
//删除角色部门表该角色所有的部门
string sql = "delete from RoleGroup where RoleID=@RoleID";
- using (DbCommand cmd=DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text,sql))
+ using (DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql))
{
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@RoleID", id, ParameterDirection.Input));
DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd, transaction);
//批插入角色部门表
using (SqlBulkCopy bulk = new SqlBulkCopy((SqlConnection)transaction.Transaction.Connection, SqlBulkCopyOptions.Default, (SqlTransaction)transaction.Transaction))
{
- bulk.BatchSize=1000;
- bulk.ColumnMappings.Add("GroupID","GroupID");
- bulk.ColumnMappings.Add("RoleID","RoleID");
+ bulk.BatchSize = 1000;
+ bulk.ColumnMappings.Add("GroupID", "GroupID");
+ bulk.ColumnMappings.Add("RoleID", "RoleID");
bulk.DestinationTableName = "RoleGroup";
bulk.WriteToServer(dt);
transaction.CommitTransaction();
@@ -283,7 +281,8 @@ namespace Bootstrap.DataAccess
ret = true;
ClearCache();
}
- catch (Exception ex) {
+ catch (Exception ex)
+ {
ExceptionManager.Publish(ex);
transaction.RollbackTransaction();
}
diff --git a/Bootstrap.DataAccess/RoleHelper.cs b/Bootstrap.DataAccess/RoleHelper.cs
index c760ab1a..68c87169 100644
--- a/Bootstrap.DataAccess/RoleHelper.cs
+++ b/Bootstrap.DataAccess/RoleHelper.cs
@@ -3,7 +3,6 @@ using Longbow.Caching;
using Longbow.Caching.Configuration;
using Longbow.Data;
using Longbow.ExceptionManagement;
-using Longbow.Data;
using System;
using System.Collections.Generic;
using System.Data;
@@ -11,7 +10,6 @@ using System.Data.Common;
using System.Data.SqlClient;
using System.Globalization;
using System.Linq;
-using System.Data.SqlClient;
namespace Bootstrap.DataAccess
{
@@ -110,9 +108,6 @@ namespace Bootstrap.DataAccess
}
return ret;
}
-
-
-
///
/// 查询某个用户所拥有的角色
///
@@ -146,7 +141,7 @@ namespace Bootstrap.DataAccess
return Roles;
}, CacheSection.RetrieveDescByKey(RoleUserIDDataKey));
}
-
+
///
/// 删除角色表
///
@@ -239,55 +234,53 @@ namespace Bootstrap.DataAccess
}, CacheSection.RetrieveDescByKey(RoleNavigationIDDataKey));
return ret;
}
- public static bool SavaRolesByMenuId(int id, string value)
+ public static bool SavaRolesByMenuId(int id, string roleIds)
{
+ var ret = false;
DataTable dt = new DataTable();
dt.Columns.Add("NavigationID", typeof(int));
dt.Columns.Add("RoleID", typeof(int));
//判断用户是否选定角色
- if (!string.IsNullOrEmpty(value))
+ if (!string.IsNullOrEmpty(roleIds))
{
- string[] roleIDs = value.Split(',');
- foreach (string roleID in roleIDs)
+ roleIds.Split(',').ToList().ForEach(roleId =>
{
DataRow row = dt.NewRow();
- row["NavigationID"] = id;
- row["RoleID"] = roleID;
- dt.Rows.Add(row);
- }
+ dt.Rows.Add(id, roleId);
+ });
}
-
- string sql = "delete from NavigationRole where NavigationID=@NavigationID;";
- using (DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql))
+ using (TransactionPackage transaction = DBAccessManager.SqlDBAccess.BeginTransaction())
{
- cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@NavigationID", id, ParameterDirection.Input));
- using (TransactionPackage transaction = DBAccessManager.SqlDBAccess.BeginTransaction())
+ try
{
- using (SqlBulkCopy bulk = new SqlBulkCopy((SqlConnection)transaction.Transaction.Connection, SqlBulkCopyOptions.Default, (SqlTransaction)transaction.Transaction))
+ // delete role from config table
+ string sql = "delete from NavigationRole where NavigationID=@NavigationID;";
+ using (DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql))
{
- bulk.BatchSize = 1000;
- bulk.DestinationTableName = "NavigationRole";
- bulk.ColumnMappings.Add("NavigationID", "NavigationID");
- bulk.ColumnMappings.Add("RoleID", "RoleID");
+ cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@NavigationID", id, ParameterDirection.Input));
+ DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd, transaction);
- bool ret = true;
- try
+ // insert batch data into config table
+ using (SqlBulkCopy bulk = new SqlBulkCopy((SqlConnection)transaction.Transaction.Connection, SqlBulkCopyOptions.Default, (SqlTransaction)transaction.Transaction))
{
- DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd, transaction);
+ bulk.BatchSize = 1000;
+ bulk.DestinationTableName = "NavigationRole";
+ bulk.ColumnMappings.Add("NavigationID", "NavigationID");
+ bulk.ColumnMappings.Add("RoleID", "RoleID");
bulk.WriteToServer(dt);
transaction.CommitTransaction();
- ClearCache();
}
- catch (Exception ex)
- {
- ExceptionManager.Publish(ex);
- ret = false;
- transaction.RollbackTransaction();
- }
- return ret;
}
+ ret = true;
+ ClearCache();
+ }
+ catch (Exception ex)
+ {
+ ExceptionManager.Publish(ex);
+ transaction.RollbackTransaction();
}
}
+ return ret;
}
// 更新缓存
private static void ClearCache(string cacheKey = null)
@@ -335,56 +328,53 @@ namespace Bootstrap.DataAccess
///
///
///
- public static bool SaveRolesByGroupId(int gid, string value)
+ public static bool SaveRolesByGroupId(int id, string roleIds)
{
+ var ret = false;
//构造表格
DataTable dt = new DataTable();
dt.Columns.Add("RoleID", typeof(int));
dt.Columns.Add("GroupID", typeof(int));
- if (!string.IsNullOrEmpty(value))
+ if (!string.IsNullOrEmpty(roleIds))
{
- string[] roles = value.Split(',');
- foreach (string role in roles)
+ roleIds.Split(',').ToList().ForEach(roleId =>
{
- DataRow r = dt.NewRow();
- r["RoleID"] = role;
- r["GroupID"] = gid;
- dt.Rows.Add(r);
+ DataRow row = dt.NewRow();
+ dt.Rows.Add(roleId,id);
+ });
+ }
+ using (TransactionPackage transaction = DBAccessManager.SqlDBAccess.BeginTransaction())
+ {
+ try
+ {
+ // delete user from config table
+ string sql = "delete from RoleGroup where GroupID=@GroupID";
+ using (DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql))
+ {
+ cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@GroupID", id, ParameterDirection.Input));
+ DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd, transaction);
+
+ // insert batch data into config table
+ using (SqlBulkCopy bulk = new SqlBulkCopy((SqlConnection)transaction.Transaction.Connection, SqlBulkCopyOptions.Default, (SqlTransaction)transaction.Transaction))
+ {
+ bulk.BatchSize = 1000;
+ bulk.DestinationTableName = "RoleGroup";
+ bulk.ColumnMappings.Add("RoleID", "RoleID");
+ bulk.ColumnMappings.Add("GroupID", "GroupID");
+ bulk.WriteToServer(dt);
+ transaction.CommitTransaction();
+ }
+ }
+ ret = true;
+ ClearCache();
+ }
+ catch (Exception ex)
+ {
+ ExceptionManager.Publish(ex);
+ transaction.RollbackTransaction();
}
}
-
- var trans = DBAccessManager.SqlDBAccess.BeginTransaction();
- try
- {
- using (DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, string.Empty))
- {
- // 执行第一个sql
- cmd.CommandText = "delete from RoleGroup where GroupID=@GroupID";
- cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@GroupID", gid, ParameterDirection.Input));
- DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd, trans);
- }
-
- using (SqlBulkCopy bulk = new SqlBulkCopy((SqlConnection)trans.Transaction.Connection, SqlBulkCopyOptions.Default, (SqlTransaction)trans.Transaction))
- {
- bulk.BatchSize = 1000;
- bulk.DestinationTableName = "RoleGroup";
- bulk.ColumnMappings.Add("RoleID", "RoleID");
- bulk.ColumnMappings.Add("GroupID", "GroupID");
- bulk.WriteToServer(dt);
- }
-
- trans.CommitTransaction();
- ClearCache();
- return true;
- }
- catch (Exception ex)
- {
- ExceptionManager.Publish(ex);
- trans.RollbackTransaction();
- return false;
- }
-
-
+ return ret;
}
}
}
\ No newline at end of file
diff --git a/Bootstrap.DataAccess/UserHelper.cs b/Bootstrap.DataAccess/UserHelper.cs
index ff081963..0d98299a 100644
--- a/Bootstrap.DataAccess/UserHelper.cs
+++ b/Bootstrap.DataAccess/UserHelper.cs
@@ -161,14 +161,11 @@ namespace Bootstrap.DataAccess
return user != null && user.Password == LgbCryptography.ComputeHash(password, user.PassSalt);
}
// 更新缓存
- private static void ClearCache()
+ private static void ClearCache(string cacheKey = null)
{
- CacheManager.Clear(key => key == UserDataKey);
- CacheManager.Clear(key => key.Contains(UserDisplayNameDataKey));
- CacheManager.Clear(key => key.Contains(UserRoleIDDataKey));
+ CacheManager.Clear(key => string.IsNullOrEmpty(cacheKey) || key == cacheKey);
}
-
///
/// 通过roleId获取所有用户
///
@@ -229,7 +226,7 @@ namespace Bootstrap.DataAccess
try
{
//删除用户角色表该角色所有的用户
- string sql = "delete from UserRole where RoleId=@RoleId";
+ string sql = "delete from UserRole where RoleID=@RoleID";
using (DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql))
{
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@RoleID", id, ParameterDirection.Input));
@@ -316,10 +313,10 @@ namespace Bootstrap.DataAccess
try
{
//删除用户角色表该角色所有的用户
- string sql = "delete from UserGroup where GroupID=@groupID";
+ string sql = "delete from UserGroup where GroupID=@GroupID";
using (DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql))
{
- cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@groupID", id, ParameterDirection.Input));
+ cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@GroupID", id, ParameterDirection.Input));
DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd, transaction);
//批插入用户角色表
using (SqlBulkCopy bulk = new SqlBulkCopy((SqlConnection)transaction.Transaction.Connection, SqlBulkCopyOptions.Default, (SqlTransaction)transaction.Transaction))