86 lines
3.0 KiB
C#
86 lines
3.0 KiB
C#
using Longbow.Data;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Data;
|
|
using System.Data.Common;
|
|
using System.Linq;
|
|
|
|
namespace Bootstrap.DataAccess.SQLite
|
|
{
|
|
/// <summary>
|
|
///
|
|
/// </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保存当前授权菜单
|
|
/// </summary>
|
|
/// <param name="roleId"></param>
|
|
/// <param name="menuIds"></param>
|
|
/// <returns></returns>
|
|
public override bool SaveMenusByRoleId(string roleId, IEnumerable<string> menuIds)
|
|
{
|
|
bool ret = false;
|
|
using (TransactionPackage transaction = DbAccessManager.DBAccess.BeginTransaction())
|
|
{
|
|
try
|
|
{
|
|
//删除菜单角色表该角色所有的菜单
|
|
string sql = $"delete from NavigationRole where RoleID = {roleId}";
|
|
using (DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql))
|
|
{
|
|
DbAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction);
|
|
//批插入菜单角色表
|
|
menuIds.ToList().ForEach(mId =>
|
|
{
|
|
cmd.CommandText = $"Insert Into NavigationRole (NavigationID, RoleID) Values ( {mId}, {roleId})";
|
|
DbAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction);
|
|
});
|
|
transaction.CommitTransaction();
|
|
}
|
|
ret = true;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
transaction.RollbackTransaction();
|
|
throw ex;
|
|
}
|
|
}
|
|
return ret;
|
|
}
|
|
}
|
|
}
|