54 lines
1.8 KiB
C#
54 lines
1.8 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>
|
|
/// 通过角色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;
|
|
}
|
|
}
|
|
}
|