Example #1
0
        public List <KeyValueVM> GetList(int roleTypeId, CateDropType cateListType, string cateIds)
        {
            //仅仅是函数不一样


            var sql = "select * from dbo.{0}(@RoleTypeId)";

            switch (cateListType)
            {
            case CateDropType.Form:
            case CateDropType.Search:
                sql = string.Format(sql, "FC_GetRoleChildrenCateIds");//包含子项
                break;

            case CateDropType.Report:
                sql = string.Format(sql, "FC_GetRoleParentCateIds");//包含父类
                break;
            }
            //生成分类ID
            var cateList = DapperHelper.SqlQuery <int>(sql, new { RoleTypeId = roleTypeId }).ToList();

            if (!string.IsNullOrEmpty(cateIds))
            {
                var cateId = cateIds.ToInts();
                cateList = cateList.Where(o => cateId.Contains(o)).ToList();
            }
            //根据Id转化为实体
            var result = DataContext.EM_Charge_Cate.Where(o => cateList.Contains(o.Id)).Select(o => new KeyValueVM()
            {
                Value = o.CateName,
                Key   = o.Id.ToString()
            }).ToList();

            return(result);
        }
Example #2
0
        public List <KeyValueVM> GetGroupList(int roleTypeId, CateDropType cateListType, string cateIds)
        {
            //仅仅是函数不一样


            var sql = "select * from dbo.{0}(@RoleTypeId)";

            switch (cateListType)
            {
            case CateDropType.Form:
            case CateDropType.Search:
                sql = string.Format(sql, "FC_GetRoleChildrenCateIds");    //包含子项
                break;

            case CateDropType.Report:
                sql = string.Format(sql, "FC_GetRoleParentCateIds");    //包含父类
                break;
            }
            //生成分类ID
            var cateList = DapperHelper.SqlQuery <int>(sql, new { RoleTypeId = roleTypeId }).ToList();

            if (!string.IsNullOrEmpty(cateIds))
            {
                var cateId = cateIds.ToInts();
                cateList = cateList.Where(o => cateId.Contains(o)).ToList();
            }
            //根据Id转化为实体
            var query = from cate in DataContext.EM_Charge_Cate
                        join pcate in DataContext.EM_Charge_Cate on cate.ParentId equals pcate.Id
                        where cateList.Contains(cate.Id)
                        select new
            {
                Value      = cate.CateName,
                Key        = cate.Id.ToString(),
                ParentId   = pcate.Id,
                ParentName = pcate.CateName
            };

            var groupList = from cate in query
                            group cate by new { cate.ParentId, cate.ParentName }
            into gCate
                select new
            {
                Key   = gCate.Key.ParentName,
                Value = gCate.Key.ParentId.ToString(),
                Items = gCate.Select(o => new KeyValueVM {
                    Key   = o.Key,
                    Value = o.Value,
                }).ToList(),
            };

            return(groupList.ToList().Select(o => new KeyValueVM()
            {
                Key = o.Key, Value = o.Value, Items = o.Items
            }).ToList());
        }