public ActionResult GetTreeSelectJson(string moduleId) { var data = _moduleButtonService.GetList(moduleId); var treeList = new List <TreeSelectModel>(); foreach (ModuleButtonBaseEntity item in data) { TreeSelectModel treeModel = new TreeSelectModel(); treeModel.id = item.F_Id; treeModel.text = item.F_FullName; treeModel.parentId = item.F_ParentId; treeList.Add(treeModel); } return(Content(treeList.TreeSelectJson())); }
public ActionResult GetPermissionTree(string roleId) { var moduledata = _moduleService.GetList(); var buttondata = _moduleButtonService.GetList(); var authorizedata = new List <RoleAuthorizeBaseEntity>(); if (!string.IsNullOrEmpty(roleId)) { authorizedata = _roleAuthorizeService.GetList(roleId); } var treeList = new List <TreeViewModel>(); foreach (ModuleBaseEntity item in moduledata) { TreeViewModel tree = new TreeViewModel(); bool hasChildren = moduledata.Count(t => t.F_ParentId == item.F_Id) == 0 ? false : true; tree.id = item.F_Id; tree.text = item.F_FullName; tree.value = item.F_EnCode; tree.parentId = item.F_ParentId; tree.isexpand = true; tree.complete = true; tree.showcheck = true; tree.checkstate = authorizedata.Count(t => t.F_ItemId == item.F_Id); tree.hasChildren = true; tree.img = item.F_Icon == "" ? "" : item.F_Icon; treeList.Add(tree); } foreach (ModuleButtonBaseEntity item in buttondata) { TreeViewModel tree = new TreeViewModel(); bool hasChildren = buttondata.Count(t => t.F_ParentId == item.F_Id) == 0 ? false : true; tree.id = item.F_Id; tree.text = item.F_FullName; tree.value = item.F_EnCode; tree.parentId = item.F_ParentId == "0" ? item.F_ModuleId : item.F_ParentId; tree.isexpand = true; tree.complete = true; tree.showcheck = true; tree.checkstate = authorizedata.Count(t => t.F_ItemId == item.F_Id); tree.hasChildren = hasChildren; tree.img = item.F_Icon == "" ? "" : item.F_Icon; treeList.Add(tree); } return(Content(treeList.TreeViewJson())); }
public async Task <bool> ActionValidate(string roleId, string action, bool isAuthorize = false) { var authorizeurldata = new List <AuthorizeActionModel>(); var rolelist = roleId.Split(','); var user = await userApp.GetForm(currentuser.UserId); if (user == null || user.F_EnabledMark == false) { return(false); } var cachedata = await CacheHelper.Get <Dictionary <string, List <AuthorizeActionModel> > >(cacheKey + "authorize_list"); if (cachedata == null) { cachedata = new Dictionary <string, List <AuthorizeActionModel> >(); } foreach (var roles in rolelist) { if (!cachedata.ContainsKey(roles)) { var moduledata = await moduleApp.GetList(); moduledata = moduledata.Where(a => a.F_EnabledMark == true).ToList(); var buttondata = await moduleButtonApp.GetList(); buttondata = buttondata.Where(a => a.F_EnabledMark == true).ToList(); var role = uniwork.IQueryable <RoleEntity>(a => a.F_Id == roles && a.F_EnabledMark == true).ToList(); if (role != null) { var authdata = new List <AuthorizeActionModel>(); var authorizedata = await GetList(roles); foreach (var item in authorizedata) { try { if (item.F_ItemType == 1) { ModuleEntity moduleEntity = moduledata.Find(t => t.F_Id == item.F_ItemId && t.F_IsPublic == false); if (moduleEntity != null) { authdata.Add(new AuthorizeActionModel { F_Id = moduleEntity.F_Id, F_UrlAddress = moduleEntity.F_UrlAddress, F_Authorize = moduleEntity.F_Authorize }); } } else if (item.F_ItemType == 2) { ModuleButtonEntity moduleButtonEntity = buttondata.Find(t => t.F_Id == item.F_ItemId && t.F_IsPublic == false); if (moduleButtonEntity != null) { authdata.Add(new AuthorizeActionModel { F_Id = moduleButtonEntity.F_ModuleId, F_UrlAddress = moduleButtonEntity.F_UrlAddress, F_Authorize = moduleButtonEntity.F_Authorize }); } } } catch (Exception ex) { string e = ex.Message; continue; } } authdata.AddRange(moduledata.Where(a => a.F_IsPublic == true).Select(a => new AuthorizeActionModel { F_Id = a.F_Id, F_UrlAddress = a.F_UrlAddress, F_Authorize = a.F_Authorize }).ToList()); authdata.AddRange(buttondata.Where(a => a.F_IsPublic == true).Select(a => new AuthorizeActionModel { F_Id = a.F_ModuleId, F_UrlAddress = a.F_UrlAddress, F_Authorize = a.F_Authorize }).ToList()); cachedata.Add(roles, authdata); authorizeurldata.AddRange(authdata); await CacheHelper.Remove(cacheKey + "authorize_list"); await CacheHelper.Set(cacheKey + "authorize_list", cachedata); } } else { authorizeurldata.AddRange(cachedata[roles]); } } var module = authorizeurldata.Find(t => t.F_UrlAddress == action); if (isAuthorize) { var temps = action.Split(','); module = authorizeurldata.Where(t => temps.Contains(t.F_Authorize)).FirstOrDefault(); } if (module != null) { return(true); } return(false); }
public async Task SubmitForm(RoleEntity roleEntity, string[] permissionIds, string[] permissionfieldsIds, string keyValue) { if (!string.IsNullOrEmpty(keyValue)) { roleEntity.F_Id = keyValue; } else { roleEntity.F_DeleteMark = false; roleEntity.F_AllowEdit = false; roleEntity.F_AllowDelete = false; roleEntity.Create(); } var moduledata = await moduleApp.GetList(); var buttondata = await moduleButtonApp.GetList(); var fieldsdata = await moduleFieldsApp.GetList(); List <RoleAuthorizeEntity> roleAuthorizeEntitys = new List <RoleAuthorizeEntity>(); foreach (var itemId in permissionIds) { RoleAuthorizeEntity roleAuthorizeEntity = new RoleAuthorizeEntity(); roleAuthorizeEntity.F_Id = Utils.GuId(); roleAuthorizeEntity.F_ObjectType = 1; roleAuthorizeEntity.F_ObjectId = roleEntity.F_Id; roleAuthorizeEntity.F_ItemId = itemId; if (moduledata.Find(t => t.F_Id == itemId) != null) { roleAuthorizeEntity.F_ItemType = 1; roleAuthorizeEntitys.Add(roleAuthorizeEntity); } if (buttondata.Find(t => t.F_Id == itemId) != null) { roleAuthorizeEntity.F_ItemType = 2; roleAuthorizeEntitys.Add(roleAuthorizeEntity); } } foreach (var itemId in permissionfieldsIds) { RoleAuthorizeEntity roleAuthorizeEntity = new RoleAuthorizeEntity(); roleAuthorizeEntity.F_Id = Utils.GuId(); roleAuthorizeEntity.F_ObjectType = 1; roleAuthorizeEntity.F_ObjectId = roleEntity.F_Id; roleAuthorizeEntity.F_ItemId = itemId; if (fieldsdata.Find(t => t.F_Id == itemId) != null) { roleAuthorizeEntity.F_ItemType = 3; roleAuthorizeEntitys.Add(roleAuthorizeEntity); } } uniwork.BeginTrans(); if (!string.IsNullOrEmpty(keyValue)) { await repository.Update(roleEntity); } else { roleEntity.F_Category = 1; await repository.Insert(roleEntity); } await uniwork.Delete <RoleAuthorizeEntity>(t => t.F_ObjectId == roleEntity.F_Id); await uniwork.Insert(roleAuthorizeEntitys); uniwork.Commit(); await CacheHelper.Remove(cacheKey + keyValue); await CacheHelper.Remove(cacheKey + "list"); await CacheHelper.Remove(authorizecacheKey + "list"); await CacheHelper.Remove(authorizecacheKey + "authorize_list"); await CacheHelper.Remove(initcacheKey + "modulebutton_list"); await CacheHelper.Remove(initcacheKey + "modulefields_list"); await CacheHelper.Remove(initcacheKey + "list"); }