public JsonMajorGroupByYears findScoreByMajorCode(string majorCode, List <int> years) { years.Sort((s1, s2) => s2.CompareTo(s1)); var jsonMajorGroupByYears = new JsonMajorGroupByYears(); var majorName = _majorRepository.findByCode(majorCode).Result.name; var colleges = new List <JsonCollegesInMajorGroupByYears>(); foreach (var y in years) { var jci = new JsonCollegesInMajorGroupByYears(); var jscgbyList = new List <JsonScoreCollegeGroupByYears>(); var majorColleges = _majorCollegeRepository.GetMajorCollegesByMajorCodeAndYear(majorCode, y).Result; foreach (var mc in majorColleges) { JsonScoreCollegeGroupByYears jscgby = new JsonScoreCollegeGroupByYears(); jscgby.groupCode = mc.groupCode; jscgby.collegeCode = mc.CollegeEntityId; jscgby.collegeName = _collegeRepository.findByCode(mc.CollegeEntityId).Result.name; jscgby.score = mc.score; jscgbyList.Add(jscgby); } jci.year = Convert.ToInt32(y); jci.colleges = jscgbyList; colleges.Add(jci); } jsonMajorGroupByYears.majorCode = majorCode; jsonMajorGroupByYears.majorName = majorName; jsonMajorGroupByYears.colleges = colleges; return(jsonMajorGroupByYears); }