public ActionResult LoadCourseInfo(int ID) { System.Diagnostics.Debug.WriteLine(ID); var CourseInfo = (from _Course in db.Courses where _Course.ID == ID select _Course).FirstOrDefault(); var Lectures = (from _Lecture in db.Lectures where _Lecture.CourseID == ID select _Lecture).ToArray<Lecture>(); JSONCourse JSONCourse = new JSONCourse(CourseInfo.ID, CourseInfo.CRN, CourseInfo.Name); foreach(var Lecture in Lectures) { JSONCourse.Lectures.Add(new JSONLecture(Lecture.ID,Lecture.Name,Lecture.CourseID,Lecture.Date)); } return Json(JSONCourse, JsonRequestBehavior.AllowGet); }
public ActionResult GetAllCourses() { string currentUser = User.Identity.GetUserName(); var _CurrUserData = (from _UserData in db.UserDatas where _UserData.UserName == currentUser select _UserData); UserData CurrUserData = _CurrUserData.FirstOrDefault(); List<JSONCourse> AllCourse = new List<JSONCourse>(); foreach (var _course in CurrUserData.Courses) { System.Diagnostics.Debug.WriteLine(CurrUserData.Courses.Count); JSONCourse JSONCourse = new JSONCourse(_course.ID, _course.CRN, _course.Name); System.Diagnostics.Debug.WriteLine(_course.Lectures.Count); foreach (var Lecture in _course.Lectures) { JSONCourse.Lectures.Add(new JSONLecture(Lecture.ID, Lecture.Name, Lecture.CourseID, Lecture.Date)); } AllCourse.Add(JSONCourse); } System.Diagnostics.Debug.WriteLine(AllCourse.Count); return Json(AllCourse, JsonRequestBehavior.AllowGet); }