예제 #1
0
        private List <GroupUserModel> GetSubTreeData(List <AdGroupUser> data, string parentCode, List <GroupUserModel> lstCategories, int tab)
        {
            var contents = parentCode == null
                ? data.Where(x => x.ParentCode == null).OrderBy(x => x.GroupUserId).ToList()
                : data.Where(x => x.ParentCode == parentCode).OrderBy(x => x.Title).ToList();

            foreach (var item in contents)
            {
                var category = new GroupUserModel
                {
                    Id        = item.GroupUserId,
                    Code      = item.GroupUserCode,
                    Title     = item.Title,
                    ParentId  = item.ParentCode,
                    IsChecked = false,
                    IsEnabled = false,
                    Level     = tab,
                    HasChild  = data.Any(x => x.ParentCode == item.GroupUserCode)
                };
                lstCategories.Add(category);
                if (category.HasChild)
                {
                    GetSubTreeData(data, item.GroupUserCode, lstCategories, tab + 1);
                }
            }
            return(lstCategories);
        }
예제 #2
0
        public object JTable([FromBody] JTableGroupUserModelCustom jTablePara)
        {
            int intBeginFor = (jTablePara.CurrentPage - 1) * jTablePara.Length;

            //if (string.IsNullOrEmpty(jTablePara.GroupCode) && string.IsNullOrEmpty(jTablePara.GroupName))
            //{
            var query = from x in _context.AdGroupUsers
                        where ((string.IsNullOrEmpty(jTablePara.GroupCode) || x.GroupUserCode.ToLower().Contains(jTablePara.GroupCode.ToLower())) &&
                               (string.IsNullOrEmpty(jTablePara.GroupName) || x.Title.ToLower().Contains(jTablePara.GroupName.ToLower())) &&
                               jTablePara.Status == null || x.IsEnabled == jTablePara.Status)
                        select new GroupUserModel
            {
                Id          = x.GroupUserId,
                Title       = x.Title,
                Code        = x.GroupUserCode,
                ParentId    = x.ParentCode,
                CreatedDate = x.CreatedDate,
                Description = x.Description,
                IsEnabled   = x.IsEnabled,
                Ord         = x.GroupUserCode == "G000" ? 1 : x.GroupUserCode == "D000" ? 2 : x.GroupUserCode == "P000" ? 4 : x.ParentCode == "D000" ? 3 : x.ParentCode == "P000" ? 5 : 6
            };

            var query2 = query.OrderBy(o => o.Ord).ThenBy(o => o.Code);//.Union(queryOrgDept).Union(queryOrgPc).ToList();
            var count  = query2.Count();

            var listGroupUser = query2.Skip(intBeginFor).Take(jTablePara.Length).ToList();

            var result = new List <GroupUserModel>();

            foreach (var gUser in listGroupUser.Where(x => string.IsNullOrEmpty(x.ParentId)).OrderBy(x => x.Id))
            {
                //gUser.Title = (gUser.Code == "G000" ? "<i class='fa fa-folder-open icon-state-warning'></i> " : gUser.Code == "D000" || gUser.Code == "P000" ? ". . . <i class='fa fa-folder-open icon-state-warning'></i> " : string.IsNullOrEmpty(gUser.ParentId) ? ". . . . . . <i class='fa fa-folder-open icon-state-warning'></i> " : ". . . . . . <i class='fa fa-folder font-green-sharp'></i> ") + gUser.Title;
                var listChild = GetGroupUserChild(query2.AsNoTracking().ToList(), gUser.Code, ". . . ");

                var groupUser = new GroupUserModel();
                groupUser.Id          = gUser.Id;
                groupUser.Title       = (listChild.Count > 0 ? "<i class='fa fa-folder-open icon-state-warning'></i> " : "<i class='fa fa-folder text-info'></i> ") + gUser.Title;
                groupUser.Code        = gUser.Code;
                groupUser.ParentId    = gUser.ParentId;
                groupUser.CreatedDate = gUser.CreatedDate;
                groupUser.Description = gUser.Description;
                groupUser.IsEnabled   = gUser.IsEnabled;
                result.Add(groupUser);
                if (listChild.Count > 0)
                {
                    result = result.Concat(listChild).ToList();
                }
            }

            var jdata = JTableHelper.JObjectTable(result, jTablePara.Draw, count, "Id", "Title", "Code", "ParentId", "CreatedDate", "Description", "IsEnabled");

            return(Json(jdata));
            //}
            //else
            //{
            //    var query = _context.VIBGroupUsers
            //        .Where(p => (string.IsNullOrEmpty(jTablePara.GroupCode) || p.ParentCode == jTablePara.GroupCode)
            //                 && (string.IsNullOrEmpty(jTablePara.GroupName) || p.Title.ToLower().Contains(jTablePara.GroupName.ToLower())))
            //        .OrderBy(x => x.Title)
            //        .Select(x => new { Id = x.GroupUserId, x.Title, Code = x.GroupUserCode, x.ParentCode, x.CreatedDate, x.Description, x.IsEnabled })
            //        .AsNoTracking();

            //    var count = query.ToList().Count();
            //    var data = query.Skip(intBeginFor).Take(jTablePara.Length).ToList();
            //    var jdata = JTableHelper.JObjectTable(data, jTablePara.Draw, count, "Id", "Title", "Code", "ParentId", "CreatedDate", "Description", "IsEnabled");
            //    return Json(jdata);
            //}
        }