List <IGrouping <bool, Tuple <string, decimal> > > Section(int sectionId) { var courseTCs = SiteObjectRelationService .GetByRelation(typeof(Section), sectionId, typeof(Course)).Select(x => x.Object_ID.ToString()) .ToList(); var parents = CourseService.GetAll(x => courseTCs.Contains(x.Course_TC) && x.IsTrack != true) .Select(x => x.ParentCourse_TC).Distinct().ToList(); var context = new RecRepository().GetContext(); var coefs = parents.SelectMany(x => GetCoefs(context, x)) .GroupBy(x => x.Item1, x => x.Item2).Select(x => Tuple.Create(x.Key, x.Sum() / x.Count())); var zero = parents.Except(coefs.Select(x => x.Item1)).Select(x => Tuple.Create(x, decimal.Zero)); coefs = coefs.Concat(zero); var coefs2 = coefs .GroupBy(x => parents.Contains(x.Item1)); return(coefs2.ToList()); }
public ActionResult CourseRecommendations(string id) { var model = new List <FullCourseCoef>(); if (!id.IsEmpty()) { var parentTC = CourseService.GetValues(id, x => x.ParentCourse_TC); var context = new RecRepository().GetContext(); var coefs = GetCoefs(context, parentTC); if (coefs.Any()) { var preCourses = CoursePrerequisiteService.GetAll(x => x.Course_TC == id) .Select(x => x.RequiredCourse.ParentCourse_TC).ToList(); coefs = coefs.Where(x => !preCourses.Contains(x.Item1)).ToList(); model = GetCourses(coefs); } } return(View(model)); }