public object G_getAllFunctionPermission(C_parameterGetAllFunctionPermission parameter) { // auto id auto incream var autoNumber = 10000000; // get data from table group in database to struture of tree js var data = _dbContext.functions.Select(x => new C_treeOfFunctionPermission { name = x.Function1, text = x.Title, id = x.Function1, Url = x.Url, isRootTree = true, arrayChildren = _dbContext.contraint_group_function_childOfFunction.Where(child => child.Function == x.Function1 && child.Group == parameter.Group).Select(child => new C_treeOfFunctionFillStringArray { name = child.ChildOfFunction }).ToList(), }).Where(x => x.Url != null && x.Url != "").ToList(); // get all table childOfFunction in database var a_getallChildOfFunction = _dbContext.childOfFunctions.Select(x => new C_treeOfFunctionPermission { name = x.ChildOfFunction1, text = x.Title, id = "isNull", parent_id = "isNull", isRootTree = false, Order = x.Order, removeFunction = x.RemoveFunction }).OrderBy(x => x.Order).ToList(); foreach (var item in data) { if (item.children == null) { item.children = new List <C_treeOfFunctionPermission>(); } foreach (var child in a_getallChildOfFunction) { if (convertNullToString(child.removeFunction).IndexOf("#" + item.name + "#") == -1) { var existsItem = item.arrayChildren.Find(x => x.name == child.name); item.children.Add(new C_treeOfFunctionPermission { name = child.name, text = child.text, id = autoNumber.ToString(), parent_id = item.id, isRootTree = false, state = new C_treeOfFunctionSelected { selected = (existsItem != null ? true : false), } }); } autoNumber++; } } // order by List <C_treeOfFunctionPermission> listAlterOrder = new List <C_treeOfFunctionPermission>(); var index = 0; foreach (var item in data) { if (item.children.Find(x => x.state.selected == true) == null) { if (index == 0) { item.state = new C_treeOfFunctionSelected { opened = true }; index++; } listAlterOrder.Add(item); } ; } ; foreach (var item in data) { if (item.children.Find(x => x.state.selected == true) != null && item.children.Find(x => x.state.selected == false) != null) { if (index == 0) { item.state = new C_treeOfFunctionSelected { opened = true }; index++; } listAlterOrder.Add(item); } ; } ; foreach (var item in data) { if (index == 0) { item.state = new C_treeOfFunctionSelected { opened = true }; index++; } if (item.children.Find(x => x.state.selected == false) == null) { listAlterOrder.Add(item); } ; } ; // return result datatype json return(Json(listAlterOrder, JsonRequestBehavior.AllowGet)); }
public object G_getAllFunctionPermission(C_parameterGetAllFunctionPermission parameter) { var itemGroup = _dbContext.contraint_account_group.FirstOrDefault(x => x.Account == parameter.Account); var Group = ""; if (itemGroup != null) { Group = itemGroup.Group; } // auto id auto incream var autoNumber = 10000000; // get data from table group in database to struture of tree js var data = _dbContext.functions.Select(x => new C_treeOfFunctionPermission { name = x.Function1, text = x.Title, id = x.Function1, Url = x.Url, isRootTree = true, arrayChildren = _dbContext.contraint_group_function_childOfFunction.Where(child => child.Function == x.Function1 && child.Group == Group).Select(child => new C_treeOfFunctionFillStringArray { name = child.ChildOfFunction }).ToList(), }).Where(x => x.Url != null && x.Url != "").ToList(); var dataOfAccount = _dbContext.contraint_account_function_childOfFunction.Select(x => new { Account = x.Account, Funciton = x.Function, childOfFunction = x.ChildOfFunction }).Where(x => x.Account == parameter.Account ).ToList(); // get all table childOfFunction in database var a_getallChildOfFunction = _dbContext.childOfFunctions.Select(x => new C_treeOfFunctionPermission { name = x.ChildOfFunction1, text = x.Title, id = "isNull", parent_id = "isNull", isRootTree = false, Order = x.Order }).OrderBy(x => x.Order).ToList(); foreach (var item in data) { if (item.children == null) { item.children = new List <C_treeOfFunctionPermission>(); } foreach (var child in a_getallChildOfFunction) { var existsItem = item.arrayChildren.Find(x => x.name == child.name); if (existsItem == null) { item.children.Add(new C_treeOfFunctionPermission { name = child.name, text = child.text, id = autoNumber.ToString(), parent_id = item.id, isRootTree = false, state = new C_treeOfFunctionSelected { selected = false } }); autoNumber++; } } } foreach (var item in dataOfAccount) { var ExistsItem = data.Find(x => x.name == item.Funciton); if (ExistsItem != null) { var ExistsItemChildren = ExistsItem.children.Find(x => x.name == item.childOfFunction); if (ExistsItemChildren != null) { ExistsItemChildren.state.selected = true; //ExistsItem.children.Add(new C_treeOfFunctionPermission //{ // name = item.childOfFunction, // text = a_getallChildOfFunction.Find(x => x.name == item.childOfFunction).text, // id = autoNumber.ToString(), // parent_id = ExistsItem.id, // isRootTree = false, // state = new C_treeOfFunctionSelected // { // selected = true // } //}); } autoNumber++; } } // order by List <C_treeOfFunctionPermission> listAlterOrder = new List <C_treeOfFunctionPermission>(); var index = 0; foreach (var item in data) { if (item.children.Count > 0 && item.children.Find(x => x.state.selected == true) == null) { if (index == 0) { item.state = new C_treeOfFunctionSelected { opened = true }; index++; } listAlterOrder.Add(item); } ; } ; foreach (var item in data) { if (item.children.Count > 0 && item.children.Find(x => x.state.selected == true) != null && item.children.Find(x => x.state.selected == false) != null) { if (index == 0) { item.state = new C_treeOfFunctionSelected { opened = true }; index++; } listAlterOrder.Add(item); } ; } ; foreach (var item in data) { if (index == 0) { item.state = new C_treeOfFunctionSelected { opened = true }; index++; } if (item.children.Count > 0 && item.children.Find(x => x.state.selected == false) == null) { listAlterOrder.Add(item); } ; } ; // return result datatype json return(Json(listAlterOrder, JsonRequestBehavior.AllowGet)); }