public object GetACtion([FromBody] TempSub obj) { try { List <string> liTemp = new List <string>(); DataDynamic liAllTemp = new DataDynamic(2); var temp = _context.AdPrivileges.Where(x => obj.IdS[0] == x.FunctionCode).Select(x => new { x.ResourceCode, x.PrivilegeId }); foreach (var item in temp) { liTemp.Add(item.ResourceCode.ToString()); liAllTemp.Data[0].Add(item.PrivilegeId); } var query = _context.AdResources.Where(x => liTemp.Contains(x.ResourceCode.ToString())).Select(x => new { x.ResourceId, x.ResourceCode, x.Title, x.Description, x.Status }); var sql = query.ToSql(); liAllTemp.Data[1].Add(query); return(Json(liAllTemp)); } catch (Exception ex) { JMessage objex = new JMessage() { Error = true, Object = ex }; return(Json(objex)); } }
public List <TreeView> GetTreeData([FromBody] TempSub obj) { //if (obj.IdI == null && obj.IdS == null) //{ // return null; //} if (obj.IdI == null) { var data = _context.UrencoAssetsCategorys.OrderBy(x => x.CatName).AsNoTracking(); var dataOrder = GetSubTreeData(data.ToList(), null, new List <TreeView>(), 0); return(dataOrder); } else { string catCode = _context.UrencoAssetsCategorys.Where(x => x.Id == obj.IdI[0]).Select(x => x.CatCode).FirstOrDefault(); var data = _context.UrencoAssetsCategorys.OrderBy(x => x.CatName).Where(x => (x.CatCode != catCode && x.CatParent != catCode)).AsNoTracking(); var dataOrder = GetSubTreeData(data.ToList(), null, new List <TreeView>(), 0); return(dataOrder); } }
public async Task <IActionResult> GetFunction([FromBody] TempSub obj) { List <FunctionModel> result = new List <FunctionModel>(); try { if (obj.IdS.Length > 0) { if (obj.IdS.Length == 3) { var appCode = obj.IdS[0]; var groupCode = obj.IdS[1]; var roleId = obj.IdS[2]; var listGroupFunction = await _context.AdPermissions.Include(i => i.Function).Where(x => x.ApplicationCode == appCode && x.GroupUserCode == groupCode && x.RoleId == roleId && x.UserId == null).GroupBy(g => g.Function).ToListAsync(); if (listGroupFunction.Count > 0) { foreach (var grpFunc in listGroupFunction) { var func = grpFunc.Key; var function = new FunctionModel(); function.Id = func.FunctionId; function.Title = func.Title; function.Code = func.FunctionCode; function.ParentCode = func.ParentCode; result.Add(function); } } } else { var appCode = obj.IdS[0]; var query = from af in _context.AdAppFunctions join fu in _context.AdFunctions on af.FunctionCode equals fu.FunctionCode where af.ApplicationCode == appCode orderby fu.Title select new FunctionModel { Id = fu.FunctionId, Title = fu.Title, Code = fu.FunctionCode, ParentCode = fu.ParentCode }; //var data = query.OrderByDescending(x => x.Title).AsNoTracking(); var listFunction = query.ToList(); if (obj.IdS.Length == 2) { var funcCode = obj.IdS[1]; var listFunctionChild = listFunction.Where(x => x.Code == funcCode).OrderByDescending(x => x.Title); foreach (var func in listFunctionChild) { var listChild = GetFunctionChild(listFunction, func.Code, 1); var function = new FunctionModel(); function.Id = func.Id; function.Title = func.Title; function.Code = func.Code; function.ParentCode = func.ParentCode; result.Add(function); if (listChild.Count > 0) { result = result.Concat(listChild).ToList(); } } var res = result.ToList(); return(Json(res)); } else { foreach (var func in listFunction.Where(x => string.IsNullOrEmpty(x.ParentCode)).OrderByDescending(x => x.Title)) { var listChild = GetFunctionChild(listFunction, func.Code, 1); var function = new FunctionModel(); function.Id = func.Id; function.Title = func.Title; function.Code = func.Code; function.ParentCode = func.ParentCode; function.Ord = 1; result.Add(function); if (listChild.Count > 0) { result = result.Concat(listChild).ToList(); } } } } } } catch (Exception ex) { JMessage objex = new JMessage() { Error = true, Object = ex }; } return(Json(result)); }