Exemplo n.º 1
0
        public JsonResult CareerDetails(int id)
        {
            try
            {
                // initialize model
                CareerDetails model = new Models.CareerDetails();
                model.Levels = new List<LevelDetails>();

                // receive career
                var career = (from c in Context.sh_careers where c.CareerID == id select c).First();
                model.CareerID = career.CareerID;
                model.Details = career.Description;

                // retrieve certifications
                var certs = (from c in Context.sh_certifications where c.sh_career_certifications.Any(car => car.CareerID == id)
                             orderby c.sh_level.Order, c.Title.ToLower() select c).ToList();

                foreach (var cert in certs)
                {
                    var levelCheck = (from l in model.Levels where l.LevelID == cert.LevelID select l);
                    LevelDetails level = new LevelDetails() { LevelID = cert.LevelID, Name = cert.sh_level.Name, Index = cert.sh_level.Order };

                    if (levelCheck.Count() > 0)
                    {
                        level = levelCheck.First();
                    }
                    else
                    {
                        model.Levels.Add(level);
                    }

                    // check for no certs
                    if (level.Certifications == null) { level.Certifications = new List<CertificationDetails>(); }
                    level.Certifications.Add(new CertificationDetails {
                        Abbreviation = cert.Abbreviation,
                        CareerTrack = cert.CareerTrack,
                        CertificationID = cert.CertificationID,
                        Details = cert.Details,
                        LevelID = cert.LevelID,
                        ProviderID = cert.ProviderID,
                        Title = cert.Title,
                        Url = cert.Url,
                        Provider = cert.sh_provider.Name
                    });
                }

                var providers = (from p in Context.sh_providers
                                 where p.sh_certifications.Any(c => c.sh_career_certifications.Any(ca => ca.CareerID == id))
                                 orderby p.sh_certifications.Count descending
                                 select new Provider
                                 {
                                     Name = p.Name,
                                     ProviderID = p.ProviderID,
                                     CertificationCount = p.sh_certifications.Where(c => c.sh_career_certifications.Any(ce => ce.CareerID == id)).Count(),
                                     Show = true
                                 }).ToList();

                // reorder items by descending and the special comptia
                providers = providers.OrderByDescending(p => p.CertificationCount).ToList();
                var comptia = (from p in providers where p.Name.Contains("CompTIA") select p).ToList();
                if (comptia.Count > 0)
                {
                    providers.Remove(comptia[0]);
                    providers.Insert(0, comptia[0]);
                }

                for (int i = 0; i < providers.Count; i++)
                {
                    providers[i].Show = i < 5;
                }

                int instructionIndex = 0;
                foreach (var level in model.Levels)
                {
                    level.Instruction = getInstruction(career, ref instructionIndex);

                    // resort providers with comptia above
                    var comptias = (from c in level.Certifications where c.Provider.Contains("CompTIA") select c).ToList();
                    foreach (var comptia2 in comptias)
                    {
                        level.Certifications.Remove(comptia2);
                        level.Certifications.Insert(0, comptia2);
                    }
                }

                return Json(new { success = true, results = model, providers = providers });
            }
            catch {}

            return Json(new { success = false });
        }
Exemplo n.º 2
0
        public JsonResult ViewAll()
        {
            try
            {
                // initialize model
                CareerDetails model = new Models.CareerDetails();
                model.Levels = new List<LevelDetails>();

                // retrieve certifications
                var certs = (from c in Context.sh_certifications
                             orderby c.LevelID, c.Title.ToLower()
                             select c).ToList();

                foreach (var cert in certs)
                {
                    var levelCheck = (from l in model.Levels where l.LevelID == cert.LevelID select l);
                    LevelDetails level = new LevelDetails() { LevelID = cert.LevelID, Name = cert.sh_level.Name, Index = cert.sh_level.Order };

                    if (levelCheck.Count() > 0)
                    {
                        level = levelCheck.First();
                    }
                    else
                    {
                        model.Levels.Add(level);
                    }

                    // check for no certs
                    if (level.Certifications == null) { level.Certifications = new List<CertificationDetails>(); }
                    level.Certifications.Add(new CertificationDetails
                    {
                        Abbreviation = cert.Abbreviation,
                        CareerTrack = cert.CareerTrack,
                        CertificationID = cert.CertificationID,
                        Details = cert.Details,
                        LevelID = cert.LevelID,
                        ProviderID = cert.ProviderID,
                        Title = cert.Title,
                        Url = cert.Url,
                        Provider = cert.sh_provider.Name
                    });
                }

                var providers = (from p in Context.sh_providers
                                 orderby p.sh_certifications.Count descending
                                 select new Provider
                                 {
                                     Name = p.Name,
                                     ProviderID = p.ProviderID,
                                     CertificationCount = p.sh_certifications.Count,
                                     Show = true
                                 }).ToList();

                for (int i = 0; i < providers.Count; i++)
                {
                    providers[i].Show = i < 5;
                }

                return Json(new { success = true, results = model, providers = providers });
            }
            catch { }

            return Json(new { success = false });
        }