2018-10-21 10:27:43 +08:00
|
|
|
|
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);
|
2018-10-23 14:28:25 +08:00
|
|
|
|
using (TransactionPackage transaction = DbAccessManager.DBAccess.BeginTransaction())
|
2018-10-19 23:09:52 +08:00
|
|
|
|
{
|
2018-10-23 14:28:25 +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>
|
2018-10-23 14:28:25 +08:00
|
|
|
|
/// <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;
|
2018-10-20 22:25:53 +08:00
|
|
|
|
using (TransactionPackage transaction = DbAccessManager.DBAccess.BeginTransaction())
|
2018-10-19 23:09:52 +08:00
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
//删除菜单角色表该角色所有的菜单
|
2018-10-29 14:29:42 +08:00
|
|
|
|
string sql = $"delete from NavigationRole where RoleID = {roleId}";
|
2018-10-20 22:25:53 +08:00
|
|
|
|
using (DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql))
|
2018-10-19 23:09:52 +08:00
|
|
|
|
{
|
2018-10-20 22:25:53 +08:00
|
|
|
|
DbAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction);
|
2018-10-19 23:09:52 +08:00
|
|
|
|
//批插入菜单角色表
|
2018-10-23 14:28:25 +08:00
|
|
|
|
menuIds.ToList().ForEach(mId =>
|
2018-10-19 23:09:52 +08:00
|
|
|
|
{
|
2018-10-23 14:28:25 +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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|