BootstrapAdmin/Bootstrap.DataAccess.SQLite/Menu.cs

87 lines
3.2 KiB
C#
Raw Normal View History

using Longbow.Data;
2018-10-19 23:09:52 +08:00
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>
2018-10-30 13:07:29 +08:00
public override bool DeleteMenu(IEnumerable<string> value)
2018-10-19 23:09:52 +08:00
{
bool ret = false;
var ids = string.Join(",", value);
using (TransactionPackage transaction = DbAccessManager.DBAccess.BeginTransaction())
2018-10-19 23:09:52 +08:00
{
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();
CacheCleanUtility.ClearCache(menuIds: value);
ret = true;
}
catch (Exception ex)
{
transaction.RollbackTransaction();
throw ex;
}
}
2018-10-19 23:09:52 +08:00
}
return ret;
}
/// <summary>
/// <summary>
/// 通过角色ID保存当前授权菜单
/// </summary>
/// <param name="roleId"></param>
2018-10-19 23:09:52 +08:00
/// <param name="menuIds"></param>
/// <returns></returns>
2018-10-30 13:07:29 +08:00
public override bool SaveMenusByRoleId(string roleId, IEnumerable<string> menuIds)
2018-10-19 23:09:52 +08:00
{
bool ret = false;
using (TransactionPackage transaction = DbAccessManager.DBAccess.BeginTransaction())
2018-10-19 23:09:52 +08:00
{
try
{
//删除菜单角色表该角色所有的菜单
string sql = $"delete from NavigationRole where RoleID = {roleId}";
using (DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql))
2018-10-19 23:09:52 +08:00
{
DbAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction);
2018-10-19 23:09:52 +08:00
//批插入菜单角色表
menuIds.ToList().ForEach(mId =>
2018-10-19 23:09:52 +08:00
{
cmd.CommandText = $"Insert Into NavigationRole (NavigationID, RoleID) Values ( {mId}, {roleId})";
DbAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction);
});
transaction.CommitTransaction();
2018-10-19 23:09:52 +08:00
}
2018-10-30 13:07:29 +08:00
CacheCleanUtility.ClearCache(menuIds: menuIds, roleIds: new List<string>() { roleId });
2018-10-19 23:09:52 +08:00
ret = true;
}
catch (Exception ex)
{
transaction.RollbackTransaction();
throw ex;
}
}
return ret;
}
}
}