2018-10-19 23:09:52 +08:00
|
|
|
|
using Bootstrap.Security;
|
2018-10-28 23:35:23 +08:00
|
|
|
|
using Bootstrap.Security.DataAccess;
|
2018-10-19 23:09:52 +08:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
|
|
|
|
namespace Bootstrap.DataAccess
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
///
|
|
|
|
|
/// </summary>
|
|
|
|
|
public class Menu : BootstrapMenu
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 删除菜单信息
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="value"></param>
|
2019-01-11 23:20:28 +08:00
|
|
|
|
public virtual bool Delete(IEnumerable<string> value)
|
2018-10-21 10:02:59 +08:00
|
|
|
|
{
|
2019-01-11 23:20:28 +08:00
|
|
|
|
var ret = false;
|
|
|
|
|
var db = DbManager.Db;
|
|
|
|
|
try
|
2018-10-21 10:02:59 +08:00
|
|
|
|
{
|
2019-01-11 23:20:28 +08:00
|
|
|
|
var ids = string.Join(",", value);
|
|
|
|
|
db.BeginTransaction();
|
|
|
|
|
db.Execute($"delete from NavigationRole where NavigationID in ({ids})");
|
|
|
|
|
db.Execute($"delete from Navigations where ID in ({ids})");
|
|
|
|
|
db.CompleteTransaction();
|
|
|
|
|
ret = true;
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
db.AbortTransaction();
|
|
|
|
|
throw ex;
|
2018-10-21 10:02:59 +08:00
|
|
|
|
}
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
2018-10-19 23:09:52 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 保存新建/更新的菜单信息
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="p"></param>
|
|
|
|
|
/// <returns></returns>
|
2019-01-11 23:20:28 +08:00
|
|
|
|
public virtual bool Save(BootstrapMenu p)
|
2018-10-21 10:02:59 +08:00
|
|
|
|
{
|
2019-01-11 23:20:28 +08:00
|
|
|
|
if (string.IsNullOrEmpty(p.Name)) throw new ArgumentNullException(nameof(p.Name));
|
|
|
|
|
|
2018-10-21 10:02:59 +08:00
|
|
|
|
if (p.Name.Length > 50) p.Name = p.Name.Substring(0, 50);
|
|
|
|
|
if (p.Icon != null && p.Icon.Length > 50) p.Icon = p.Icon.Substring(0, 50);
|
|
|
|
|
if (p.Url != null && p.Url.Length > 4000) p.Url = p.Url.Substring(0, 4000);
|
2019-01-11 23:20:28 +08:00
|
|
|
|
DbManager.Db.Save(p);
|
|
|
|
|
return true;
|
2018-10-21 10:02:59 +08:00
|
|
|
|
}
|
2018-10-19 23:09:52 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 查询某个角色所配置的菜单
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="roleId"></param>
|
|
|
|
|
/// <returns></returns>
|
2018-10-31 16:50:55 +08:00
|
|
|
|
public virtual IEnumerable<object> RetrieveMenusByRoleId(string roleId)
|
2018-10-21 10:02:59 +08:00
|
|
|
|
{
|
2019-01-11 23:20:28 +08:00
|
|
|
|
var menus = DbManager.Db.Fetch<BootstrapMenu>("select NavigationID as Id from NavigationRole where RoleID = @0", roleId);
|
2018-11-02 12:44:27 +08:00
|
|
|
|
return menus.Select(m => new { m.Id });
|
2018-10-21 10:02:59 +08:00
|
|
|
|
}
|
2018-10-19 23:09:52 +08:00
|
|
|
|
/// <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 virtual bool SaveMenusByRoleId(string roleId, IEnumerable<string> menuIds)
|
2018-10-21 10:02:59 +08:00
|
|
|
|
{
|
|
|
|
|
bool ret = false;
|
2019-01-11 23:20:28 +08:00
|
|
|
|
var db = DbManager.Db;
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
db.BeginTransaction();
|
|
|
|
|
db.Execute("delete from NavigationRole where RoleID = @0", roleId);
|
|
|
|
|
db.InsertBulk("NavigationRole", menuIds.Select(g => new { NavigationID = g, RoleID = roleId }));
|
|
|
|
|
db.CompleteTransaction();
|
|
|
|
|
ret = true;
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
2018-10-21 10:02:59 +08:00
|
|
|
|
{
|
2019-01-11 23:20:28 +08:00
|
|
|
|
db.AbortTransaction();
|
|
|
|
|
throw ex;
|
2018-10-21 10:02:59 +08:00
|
|
|
|
}
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
2018-10-19 23:09:52 +08:00
|
|
|
|
/// <summary>
|
2018-10-30 13:07:29 +08:00
|
|
|
|
/// 通过当前用户名获得所有菜单
|
2018-10-19 23:09:52 +08:00
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="userName">当前登陆的用户名</param>
|
|
|
|
|
/// <returns></returns>
|
2018-10-28 23:35:23 +08:00
|
|
|
|
public virtual IEnumerable<BootstrapMenu> RetrieveAllMenus(string userName) => DbHelper.RetrieveAllMenus(userName);
|
2018-10-19 23:09:52 +08:00
|
|
|
|
}
|
|
|
|
|
}
|