From 2edaf9b961b4e9257741e08a36ac461ea067d152 Mon Sep 17 00:00:00 2001 From: Argo-MacBookPro Date: Fri, 2 Nov 2018 19:25:31 +0800 Subject: [PATCH] =?UTF-8?q?=E9=87=8D=E6=9E=84=E4=BB=A3=E7=A0=81=EF=BC=9ARo?= =?UTF-8?q?le=E7=A7=BB=E9=99=A4Proc=5FDeleteRoles?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Bootstrap.DataAccess.MySQL/Role.cs | 38 ----------------------------- Bootstrap.DataAccess.SQLite/Role.cs | 38 ----------------------------- Bootstrap.DataAccess/Role.cs | 28 ++++++++++++++++++--- 3 files changed, 25 insertions(+), 79 deletions(-) diff --git a/Bootstrap.DataAccess.MySQL/Role.cs b/Bootstrap.DataAccess.MySQL/Role.cs index 7d79dc5e..bc146056 100644 --- a/Bootstrap.DataAccess.MySQL/Role.cs +++ b/Bootstrap.DataAccess.MySQL/Role.cs @@ -94,44 +94,6 @@ namespace Bootstrap.DataAccess.MySQL return ret; } - /// - /// 删除角色表 - /// - /// - public override bool DeleteRole(IEnumerable value) - { - bool ret = false; - var ids = string.Join(",", value); - using (TransactionPackage transaction = DbAccessManager.DBAccess.BeginTransaction()) - { - using (DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, $"delete from UserRole where RoleID in ({ids})")) - { - try - { - DbAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction); - - cmd.CommandText = $"delete from RoleGroup where RoleID in ({ids})"; - DbAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction); - - cmd.CommandText = $"delete from NavigationRole where RoleID in ({ids})"; - DbAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction); - - cmd.CommandText = $"delete from Roles where ID in ({ids})"; - DbAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction); - - transaction.CommitTransaction(); - ret = true; - } - catch (Exception ex) - { - transaction.RollbackTransaction(); - throw ex; - } - } - } - return ret; - } - /// /// /// diff --git a/Bootstrap.DataAccess.SQLite/Role.cs b/Bootstrap.DataAccess.SQLite/Role.cs index 4968527c..109fb23c 100644 --- a/Bootstrap.DataAccess.SQLite/Role.cs +++ b/Bootstrap.DataAccess.SQLite/Role.cs @@ -50,44 +50,6 @@ namespace Bootstrap.DataAccess.SQLite return ret; } - /// - /// 删除角色表 - /// - /// - public override bool DeleteRole(IEnumerable value) - { - bool ret = false; - var ids = string.Join(",", value); - using (TransactionPackage transaction = DbAccessManager.DBAccess.BeginTransaction()) - { - using (DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, $"delete from UserRole where RoleID in ({ids})")) - { - try - { - DbAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction); - - cmd.CommandText = $"delete from RoleGroup where RoleID in ({ids})"; - DbAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction); - - cmd.CommandText = $"delete from NavigationRole where RoleID in ({ids})"; - DbAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction); - - cmd.CommandText = $"delete from Roles where ID in ({ids})"; - DbAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction); - - transaction.CommitTransaction(); - ret = true; - } - catch (Exception ex) - { - transaction.RollbackTransaction(); - throw ex; - } - } - } - return ret; - } - /// /// /// diff --git a/Bootstrap.DataAccess/Role.cs b/Bootstrap.DataAccess/Role.cs index b7a684e8..f9d04fb3 100644 --- a/Bootstrap.DataAccess/Role.cs +++ b/Bootstrap.DataAccess/Role.cs @@ -139,10 +139,32 @@ namespace Bootstrap.DataAccess { bool ret = false; var ids = string.Join(",", value); - using (DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.StoredProcedure, "Proc_DeleteRoles")) + using (TransactionPackage transaction = DbAccessManager.DBAccess.BeginTransaction()) { - cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@ids", ids)); - ret = DbAccessManager.DBAccess.ExecuteNonQuery(cmd) == -1; + using (DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, $"delete from UserRole where RoleID in ({ids})")) + { + try + { + DbAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction); + + cmd.CommandText = $"delete from RoleGroup where RoleID in ({ids})"; + DbAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction); + + cmd.CommandText = $"delete from NavigationRole where RoleID in ({ids})"; + DbAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction); + + cmd.CommandText = $"delete from Roles where ID in ({ids})"; + DbAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction); + + transaction.CommitTransaction(); + ret = true; + } + catch (Exception ex) + { + transaction.RollbackTransaction(); + throw ex; + } + } } return ret; }