重构代码:Menu移除存储过程Proc_DeleteMenus

This commit is contained in:
Argo-MacBookPro 2018-11-02 19:16:03 +08:00
parent cbafbebc1f
commit ab6d78eb20
3 changed files with 20 additions and 68 deletions

View File

@ -51,38 +51,6 @@ namespace Bootstrap.DataAccess.MySQL
return menus;
}
/// <summary>
/// 删除菜单信息
/// </summary>
/// <param name="value"></param>
public override bool DeleteMenu(IEnumerable<string> 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 NavigationRole where NavigationID in ({ids})"))
{
try
{
DbAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction);
cmd.CommandText = $"delete from Navigations where ID in ({ids})";
DbAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction);
transaction.CommitTransaction();
ret = true;
}
catch (Exception ex)
{
transaction.RollbackTransaction();
throw ex;
}
}
}
return ret;
}
/// <summary>
/// <summary>
/// 通过角色ID保存当前授权菜单

View File

@ -12,38 +12,6 @@ namespace Bootstrap.DataAccess.SQLite
/// </summary>
public class Menu : DataAccess.Menu
{
/// <summary>
/// 删除菜单信息
/// </summary>
/// <param name="value"></param>
public override bool DeleteMenu(IEnumerable<string> 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 NavigationRole where NavigationID in ({ids})"))
{
try
{
DbAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction);
cmd.CommandText = $"delete from Navigations where ID in ({ids})";
DbAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction);
transaction.CommitTransaction();
ret = true;
}
catch (Exception ex)
{
transaction.RollbackTransaction();
throw ex;
}
}
}
return ret;
}
/// <summary>
/// <summary>
/// 通过角色ID保存当前授权菜单
@ -66,7 +34,7 @@ namespace Bootstrap.DataAccess.SQLite
//批插入菜单角色表
menuIds.ToList().ForEach(mId =>
{
cmd.CommandText = $"Insert Into NavigationRole (NavigationID, RoleID) Values ( {mId}, {roleId})";
cmd.CommandText = $"Insert Into NavigationRole (NavigationID, RoleID) Values ({mId}, {roleId})";
DbAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction);
});
transaction.CommitTransaction();

View File

@ -23,10 +23,26 @@ namespace Bootstrap.DataAccess
{
bool ret = false;
var ids = string.Join(",", value);
using (DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.StoredProcedure, "Proc_DeleteMenus"))
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 NavigationRole where NavigationID in ({ids})"))
{
try
{
DbAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction);
cmd.CommandText = $"delete from Navigations where ID in ({ids})";
DbAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction);
transaction.CommitTransaction();
ret = true;
}
catch (Exception ex)
{
transaction.RollbackTransaction();
throw ex;
}
}
}
return ret;
}