/// <summary> /// 获得某个角色的权限 /// </summary> /// <param name="RoleNum"></param> /// <returns></returns> public List <SysResourceEntity> GetRoleResource(string RoleNum) { List <SysResourceEntity> ListResult = CacheHelper.Get(string.Format(CacheKey.JOOSHOW_ROLEPOWER_CACHE, RoleNum)) as List <SysResourceEntity>; if (ListResult.IsNullOrEmpty()) { SysResourceProvider provider = new SysResourceProvider(); List <SysResourceEntity> ListSource = provider.GetList(); ListSource = ListSource.IsNull() ? new List <SysResourceEntity>() : ListSource; ListSource = JsonConvert.DeserializeObject <List <SysResourceEntity> >(JsonConvert.SerializeObject(ListSource)); List <SysRelationEntity> ListRole = GetList(RoleNum); ListRole = ListRole.IsNull() ? new List <SysRelationEntity>() : ListRole; ListResult = ListSource.Where(a => ListRole.Exists(b => b.ResNum == a.ResNum)).ToList(); //超级管理员权限 if (RoleNum == ResourceManager.GetSettingEntity("Super_AdminRole").Value) { ListResult = ListSource; } if (!ListResult.IsNullOrEmpty()) { CacheHelper.Insert(string.Format(CacheKey.JOOSHOW_ROLEPOWER_CACHE, RoleNum), ListResult, null, DateTime.Now.AddDays(1)); } } return(ListResult); }
/// <summary> /// 获得某个角色的权限 /// </summary> /// <param name="RoleNum"></param> /// <returns></returns> public List<SysResourceEntity> GetRoleResource(string RoleNum) { List<SysResourceEntity> ListResult = CacheHelper.Get(string.Format(CacheKey.JOOSHOW_ROLEPOWER_CACHE, RoleNum)) as List<SysResourceEntity>; if (ListResult.IsNullOrEmpty()) { SysResourceProvider provider = new SysResourceProvider(); List<SysResourceEntity> ListSource = provider.GetList(); ListSource = ListSource.IsNull() ? new List<SysResourceEntity>() : ListSource; ListSource = JsonConvert.DeserializeObject<List<SysResourceEntity>>(JsonConvert.SerializeObject(ListSource)); List<SysRelationEntity> ListRole = GetList(RoleNum); ListRole = ListRole.IsNull() ? new List<SysRelationEntity>() : ListRole; ListResult = ListSource.Where(a => ListRole.Exists(b => b.ResNum == a.ResNum)).ToList(); //超级管理员权限 if (RoleNum == ResourceManager.GetSettingEntity("Super_AdminRole").Value) { ListResult = ListSource; } if (!ListResult.IsNullOrEmpty()) { CacheHelper.Insert(string.Format(CacheKey.JOOSHOW_ROLEPOWER_CACHE, RoleNum), ListResult, null, DateTime.Now.AddDays(1)); } } return ListResult; }
/// <summary> /// 获得权限分配 /// </summary> /// <param name="roleNum"></param> /// <returns></returns> public Params<List<SysResourceEntity>, List<SysResourceEntity>, List<SysResourceEntity>> GetRole(string roleNum) { Params<List<SysResourceEntity>, List<SysResourceEntity>, List<SysResourceEntity>> param = new Params<List<SysResourceEntity>, List<SysResourceEntity>, List<SysResourceEntity>>(); SysResourceProvider provider = new SysResourceProvider(); param.Item1 = provider.GetList(); param.Item2 = GetRoleResource(roleNum); param.Item1 = param.Item1.IsNull() ? new List<SysResourceEntity>() : param.Item1; param.Item2 = param.Item2.IsNull() ? new List<SysResourceEntity>() : param.Item2; param.Item3 = param.Item1.Where(a => !param.Item2.Exists(b => b.ResNum == a.ResNum)).ToList(); param.Item3 = param.Item3.IsNull() ? new List<SysResourceEntity>() : param.Item3; List<SysResourceEntity> listTemp = new List<SysResourceEntity>(); foreach (SysResourceEntity item in param.Item2) { if (!item.ParentNum.IsEmpty() && !param.Item2.Exists(a => a.ResNum == item.ParentNum)) { SysResourceEntity entity = param.Item1.First(a => a.ResNum == item.ParentNum); if (!listTemp.Exists(a => a.ResNum == entity.ResNum)) { listTemp.Add(entity); } if (!entity.ParentNum.IsEmpty() && !param.Item2.Exists(a => a.ResNum == entity.ParentNum)) { entity = param.Item1.First(a => a.ResNum == entity.ParentNum); if (!listTemp.Exists(a => a.ResNum == entity.ResNum)) { listTemp.Add(entity); } } } } param.Item2.AddRange(listTemp); listTemp = new List<SysResourceEntity>(); if (!param.Item3.IsNullOrEmpty()) { foreach (SysResourceEntity item in param.Item3) { if (!item.ParentNum.IsEmpty() && !param.Item3.Exists(a => a.ResNum == item.ParentNum)) { SysResourceEntity entity = param.Item1.First(a => a.ResNum == item.ParentNum); if (!listTemp.Exists(a => a.ResNum == entity.ResNum)) { listTemp.Add(entity); } if (!entity.ParentNum.IsEmpty() && !param.Item3.Exists(a => a.ResNum == entity.ParentNum)) { entity = param.Item1.First(a => a.ResNum == entity.ParentNum); if (!listTemp.Exists(a => a.ResNum == entity.ResNum)) { listTemp.Add(entity); } } } } } param.Item3.AddRange(listTemp); return param; }
/// <summary> /// 获得权限分配 /// </summary> /// <param name="roleNum"></param> /// <returns></returns> public Params <List <SysResourceEntity>, List <SysResourceEntity>, List <SysResourceEntity> > GetRole(string roleNum) { Params <List <SysResourceEntity>, List <SysResourceEntity>, List <SysResourceEntity> > param = new Params <List <SysResourceEntity>, List <SysResourceEntity>, List <SysResourceEntity> >(); SysResourceProvider provider = new SysResourceProvider(); param.Item1 = provider.GetList(); param.Item2 = GetRoleResource(roleNum); param.Item1 = param.Item1.IsNull() ? new List <SysResourceEntity>() : param.Item1; param.Item2 = param.Item2.IsNull() ? new List <SysResourceEntity>() : param.Item2; param.Item3 = param.Item1.Where(a => !param.Item2.Exists(b => b.ResNum == a.ResNum)).ToList(); param.Item3 = param.Item3.IsNull() ? new List <SysResourceEntity>() : param.Item3; List <SysResourceEntity> listTemp = new List <SysResourceEntity>(); foreach (SysResourceEntity item in param.Item2) { if (!item.ParentNum.IsEmpty() && !param.Item2.Exists(a => a.ResNum == item.ParentNum)) { SysResourceEntity entity = param.Item1.First(a => a.ResNum == item.ParentNum); if (!listTemp.Exists(a => a.ResNum == entity.ResNum)) { listTemp.Add(entity); } if (!entity.ParentNum.IsEmpty() && !param.Item2.Exists(a => a.ResNum == entity.ParentNum)) { entity = param.Item1.First(a => a.ResNum == entity.ParentNum); if (!listTemp.Exists(a => a.ResNum == entity.ResNum)) { listTemp.Add(entity); } } } } param.Item2.AddRange(listTemp); listTemp = new List <SysResourceEntity>(); if (!param.Item3.IsNullOrEmpty()) { foreach (SysResourceEntity item in param.Item3) { if (!item.ParentNum.IsEmpty() && !param.Item3.Exists(a => a.ResNum == item.ParentNum)) { SysResourceEntity entity = param.Item1.First(a => a.ResNum == item.ParentNum); if (!listTemp.Exists(a => a.ResNum == entity.ResNum)) { listTemp.Add(entity); } if (!entity.ParentNum.IsEmpty() && !param.Item3.Exists(a => a.ResNum == entity.ParentNum)) { entity = param.Item1.First(a => a.ResNum == entity.ParentNum); if (!listTemp.Exists(a => a.ResNum == entity.ResNum)) { listTemp.Add(entity); } } } } } param.Item3.AddRange(listTemp); return(param); }
public ActionResult GetMenuList(int pageIndex, int pageSize, string resName, string parentNum) { SysResourceProvider provider = new SysResourceProvider(); List<SysResourceEntity> list = provider.GetList(); if (!list.IsNullOrEmpty()) { List<SysResourceEntity> listResult = list; if (!resName.IsEmpty()) { listResult = listResult.Where(a => a.ResName.Contains(resName)).ToList(); } if (!parentNum.IsEmpty()) { listResult = listResult.Where(a => a.ParentNum.Contains(parentNum)).ToList(); } List<SysResourceEntity> returnList = listResult.Skip((pageIndex - 1) * pageSize).Take(pageSize).OrderByDescending(a => a.ID).ToList(); this.ReturnJson.AddProperty("Data", ConvertJson.ListToJson<SysResourceEntity>(returnList, "List")); this.ReturnJson.AddProperty("RowCount", listResult.Count); } return Content(this.ReturnJson.ToString()); }
/// <summary> /// 设置导航信息 /// </summary> private void SetNav() { StringBuilder sb = new StringBuilder(); sb.Append("<ul class=\"breadcrumb\">"); sb.Append("<li>"); sb.Append("<i class=\"icon-home\"></i>"); sb.Append("<a href=\"/Home/Welcome\">首页</a>"); sb.Append("<i class=\"icon-angle-right\"></i>"); sb.Append("</li>"); if (IsLogin() && !this.LoginUser.RoleNum.IsEmpty()) { PowerProvider provider = new PowerProvider(); SysResourceProvider SysResourceProvider = new SysResourceProvider(); List<SysResourceEntity> listSource = SysResourceProvider.GetList(); List<SysResourceEntity> list = provider.GetRoleResource(this.LoginUser.RoleNum); if (!list.IsNullOrEmpty()) { SysResourceEntity item = list.SingleOrDefault(a => a.Url.ToLower() == this.Path.ToLower()); List<SysResourceEntity> listResult = new List<SysResourceEntity>(); while (item != null) { listResult.Insert(0, item); if (item.ParentNum.IsEmpty()) { break; } else { if (listSource.Exists(a => a.ResNum == item.ParentNum)) { item = listSource.First(a => a.ResNum == item.ParentNum); } else { break; } } } for (int i = 0; i < listResult.Count; i++) { if (i != listResult.Count - 1) { sb.Append("<li>"); sb.AppendFormat("<a href=\"{0}\">{1}</a>", listResult[i].Url.IsEmpty() ? "javascript:void(0)" : listResult[i].Url, listResult[i].ResName); sb.Append("<i class=\"icon-angle-right\"></i>"); sb.Append("</li>"); } else { sb.Append("<li>"); sb.AppendFormat("<a href=\"javascript:void(0)\">{0}</a>", listResult[i].ResName); sb.Append("</li>"); } } } } sb.Append("</ul>"); ViewBag.NavMenu = sb.ToString(); }
/// <summary> /// 获得父类菜单 /// </summary> /// <param name="parentNum"></param> /// <returns></returns> public static string GetParentMenu(string parentNum) { SysResourceProvider sysRes = new SysResourceProvider(); List<SysResourceEntity> list = sysRes.GetList(); StringBuilder sb = new StringBuilder(); string menuTemplate = "<option value='{0}' {1}>{2}</option>"; sb.AppendFormat(menuTemplate, "", "", "请选择"); if (!list.IsNullOrEmpty()) { foreach (SysResourceEntity entity in list.Where(a => a.ResType == (short)EResourceType.Page)) { sb.AppendFormat(menuTemplate, entity.ResNum, entity.ResNum == parentNum ? "selected='selected'" : string.Empty, entity.ResName); } } return sb.ToString(); }