private List <TreeViewObject> buildTreeApplication(List <Application> application, string userName, long?Role) { CacheUser cacheUser = LVCacheHelper.GetCacheUser(userName); if (cacheUser == null) { return(null); } int indexs = 1; var roleList = cacheUser.roleList.Where(x => x.RoleID == Role).FirstOrDefault();; if (roleList != null) { foreach (var item in application) { foreach (var app in roleList.application) { item.IsShow = app.AppFuncID == item.AppFuncID ? true : false; if (item.IsShow == true) { break; } } } } var parent = application.Where(x => x.PAppFuncID == null).ToList(); List <TreeViewObject> treeParent = new List <TreeViewObject>(); foreach (var item in parent) { Application applications = new Application(); applications.AppFunctions = item.AppFunctions; applications.Badge = item.Badge; applications.IsLongTile = item.IsLongTile; applications.AppFuncID = item.AppFuncID; applications.IconPath = item.IconPath; applications.LandingPageURL = item.LandingPageURL; applications.PAppFuncID = item.PAppFuncID; applications.Idx = item.Idx; applications.AppTitle = item.AppTitle.Replace("|n|", ""); applications.AppDesc = item.AppDesc; applications.ColorSchema = item.ColorSchema; applications.Colors = string.IsNullOrEmpty(item.ColorSchema) ? null : item.ColorSchema.Split(';'); applications.NotDisplayed = item.NotDisplayed; applications.FuncType = item.FuncType; var trs = new TreeViewObject() { application = applications }; buildTree(trs, application); trs.dataindex = indexs; treeParent.Add(trs); indexs++; } return(treeParent); }
public static void initCacheLogin(string userName, string PersonName, long Code, long accountID, long personID) { if (_cacheUser.ContainsKey(userName)) { return; } lock (_cacheUser) { CacheUser c = new CacheUser(); using (LV.Core.DAL.EntityFramework.EFDALContainer ef = new Core.DAL.EntityFramework.EFDALContainer()) { var obj = new object[1] { accountID }; c.PersonID = personID; c.AccountID = accountID; c.PersonName = PersonName; c.Code = Code; DataSet model = ef.Repository.ExecuteStoreScalar("usp_GetPerApplication", obj); DataTable dt = model.Tables[0]; Dictionary <byte, string> PermissionList = GetPermission(); c.PrivilegeRole = new List <PrivilegeRole>(); List <Application> functionPermision = new List <Application>(); foreach (DataRow item in dt.Rows) { PrivilegeRole p = new PrivilegeRole(); p.AppFuncID = item.IsNull("AppFuncID") ? 0 : item.Field <long>("AppFuncID"); p.PermVals = item.IsNull("PermVals") ? (byte)0 : item.Field <byte>("PermVals"); p.PersPer = GetPerListValue(p.PermVals, PermissionList); c.PrivilegeRole.Add(p); Application application = new Application(); application.AppFunctions = item.Field <string>("AppFunctions"); application.Badge = item.Field <string>("Badge"); application.IsLongTile = item.IsNull("IsLongTile") ? false : item.Field <bool>("IsLongTile"); application.AppFuncID = item.IsNull("AppFuncID") ? 0 : item.Field <long>("AppFuncID"); application.IconPath = item.Field <string>("IconPath"); application.LandingPageURL = item.Field <string>("LandingPageURL"); application.PAppFuncID = item.IsNull("PAppFuncID") ? 0 : item.Field <long>("PAppFuncID"); application.Idx = item.IsNull("Idx") ? (byte)0 : item.Field <byte>("Idx"); application.AppTitle = item.Field <string>("AppTitle").Replace("|n|", ""); application.AppDesc = item.Field <string>("AppDesc"); application.ColorSchema = item.Field <string>("ColorSchema"); application.NotDisplayed = item.IsNull("NotDisplayed") ? false : item.Field <bool>("NotDisplayed"); application.FuncType = item.Field <string>("FuncType"); functionPermision.Add(application); } //Danh sach role cua user c.roleList = (from h in ef.Repository.GetQuery <PersonRole>() join i in ef.Repository.GetQuery <Person>() on h.PersonID equals i.PersonID join j in ef.Repository.GetQuery <refRole>() on h.RoleID equals j.RoleID where h.PersonID == Code select new RoleList { RoleID = h.RoleID, RoleName = j.RoleName, IsPrimaryRole = h.IsPrimaryRole, }).ToList(); var ApplicationList = ef.Repository.GetQuery <Application>().ToList(); foreach (var role in c.roleList) { List <Realms> applicationByRole = (from h in ef.Repository.GetQuery <Realms>() where h.RoleID == role.RoleID select h).ToList(); role.application = (from h in functionPermision join k in applicationByRole on h.AppFuncID equals k.AppFuncID select h).ToList(); } // //var applicationList = _cacheGolbal.Application.ToList(); //var results = c.FunctionPermision.DistinctBy(x => x.PAppFuncID).ToList(); //c.treeFunction = new List<TreeViewObject>(); //foreach (var item in results) //{ // var row = applicationList.Where(x => x.AppFuncID == item.PAppFuncID).FirstOrDefault(); // while (row.PAppFuncID != null) // { // if (row != null) // { // var check = c.FunctionPermision.Where(x => x.AppFuncID == row.AppFuncID).FirstOrDefault(); // if (check == null) // { // c.FunctionPermision.Add(row); // } // row = applicationList.Where(x => x.AppFuncID == row.PAppFuncID).FirstOrDefault(); // if (row == null) // { // break; // } // } // else // { // break; // } // } // if (row.PAppFuncID == null) // { // var check = c.FunctionPermision.Where(x => x.AppFuncID == row.AppFuncID).FirstOrDefault(); // if (check == null) // { // c.FunctionPermision.Add(row); // } // } //} //var parent = c.FunctionPermision.Where(x => x.PAppFuncID == null).ToList(); //foreach (var item in parent) //{ // Application application = new Application(); // application.AppFunctions = item.AppFunctions; // application.Badge = item.Badge; // application.IsLongTile = item.IsLongTile; // application.AppFuncID = item.AppFuncID; // application.IconPath = item.IconPath; // application.LandingPageURL = item.LandingPageURL; // application.PAppFuncID = item.PAppFuncID; // application.Idx = item.Idx; // application.AppTitle = item.AppTitle.Replace("|n|", ""); // application.AppDesc = item.AppDesc; // application.ColorSchema = item.ColorSchema; // application.NotDisplayed = item.NotDisplayed; // application.FuncType = item.FuncType; // var trs = new TreeViewObject() { application = application }; // buildTree(trs, c.FunctionPermision); // c.treeFunction.Add(trs); //} _cacheUser.Add(userName, c); } } }