using System.Collections.Generic;
using System.Linq;
namespace BLL
{
public class Sys_RolePowerService
{
///
/// 增加角色权限
///
///
public static void SaveRolePower(Model.Sys_RolePower power)
{
string newRolePower = BLL.SQLHelper.GetNewID(typeof(Model.Sys_RolePower));
Model.Sys_RolePower newPower = new Model.Sys_RolePower();
newPower.RolePowerId = newRolePower;
newPower.RoleId = power.RoleId;
newPower.MenuId = power.MenuId;
Funs.DB.Sys_RolePower.InsertOnSubmit(newPower);
Funs.DB.SubmitChanges();
}
///
/// 删除权限
///
///
public static void DeleteRolePower(string roleId)
{
var q = from x in Funs.DB.Sys_RolePower
join y in Funs.DB.Sys_Menu on x.MenuId equals y.MenuId
where x.RoleId == roleId
select x;
if (q.Count() > 0)
{
Funs.DB.Sys_RolePower.DeleteAllOnSubmit(q);
}
Funs.DB.SubmitChanges();
}
///
/// 获取角色权限
///
///
public static List GetRolePower(string roleId)
{
List powerList = Funs.DB.Sys_RolePower.Where(e => e.RoleId == roleId).ToList();
return powerList;
}
///
/// 根据角色Id查询所有系统功能授权信息的数量
///
/// 角色Id
/// 授权的数量
public static int GetPostPowerCountByPostId(string roleId)
{
var q = (from x in Funs.DB.Sys_RolePower where x.RoleId == roleId select x).ToList();
return q.Count();
}
///
/// 根据角色主键获得角色权限数量
///
/// 角色
///
public static int GetPostPowerCountByRoleId(string roleId)
{
var q = (from x in Funs.DB.Sys_RolePower where x.RoleId == roleId select x).ToList();
return q.Count();
}
///
/// 根据角色主键获得对应的菜单权限
///
/// 角色主键
/// 菜单ID数组
public static string[] GetMenuIdByRoleId(string roleId)
{
var q = Funs.DB.Sys_RolePower.Where(e => e.RoleId == roleId);
string[] menuId = new string[q.Count()];
if (q.Count() > 0)
{
int i = 0;
foreach (var menu in q)
{
menuId[i] = menu.MenuId;
i++;
}
return menuId;
}
else
{
return null;
}
}
}
}