예제 #1
0
        public List <object> GroupSkillsForIndustry(string industryId, int langId = 1)
        {
            List <object> ds;

            using (var db = new LMISEntities())
            {
                ds = db.Skills.Where(a => a.IndustryId == industryId)
                     .Select(a => a.SkillID)
                     .Distinct()
                     .GroupJoin(
                    db.Skills.Where(a => a.IndustryId == industryId),
                    a => a, b => b.SkillID, (k, g) => new
                {
                    SkillId   = k,
                    SkillDesc = SqlUdf.SubCodeName(k, langId),
                    Levels    = g.Select(a => new
                    {
                        id   = a.SkillLevel_ID,
                        desc = SqlUdf.SubCodeName(a.SkillLevel_ID, langId)
                    }),
                    TypeIsRequired = (SqlUdf.SubCodeParent(k) == "02000003")     //For Lingual Skills Only
                })
                     .ToList()
                     .GroupJoin(
                    db.SubCodes.Where(a => a.GeneralID == "022")     //Skill Types
                    .Select(a => new
                {
                    id   = a.SubID,
                    desc = SqlUdf.SubCodeName(a.SubID, langId)
                })
                    .Distinct(),
                    a => true, b => true, (k, g) => new
                {
                    id    = k.SkillId,
                    desc  = k.SkillDesc,
                    Types = k.TypeIsRequired ? g.ToList() : g.ToList().TakeWhile(a => false),
                    k.Levels
                })
                     .SelectMany(a => a.Types.DefaultIfEmpty(new { id = "", desc = "" }), (p, c) => new
                {
                    id      = industryId + "|" + p.id + "|" + c.id,
                    desc    = p.desc + (c.id == "" ? "" : " [" + c.desc + "]"),
                    options = p.Levels.Select(a => new
                    {
                        id    = industryId + "|" + p.id + "|" + c.id + "|" + a.id,
                        desc  = a.desc + ": " + p.desc + (c.id == "" ? "" : " [" + c.desc + "]"),
                        Skill = new { p.id, p.desc },
                        Type  = (c.id == "" ? null : c),
                        Level = a
                    })
                })
                     .ToList()
                     .Cast <object>().ToList();
            }

            return(ds);
        }