public static bool AddCourseToRecommendation(COURSE course, RECOMMENDATION reco) { using (CloudEDUEntities ctx = new CloudEDUEntities()) { try { var rc = ctx.RECOMMENDATIONs.Include("COURSEs").Where(r => r.ID == reco.ID).FirstOrDefault(); var cs = ctx.COURSEs.Where(c => c.ID == course.ID).FirstOrDefault(); rc.COURSEs.Add(cs); ctx.Entry(rc).State = System.Data.EntityState.Modified; ctx.SaveChanges(); } catch (Exception e) { System.Diagnostics.Debug.WriteLine(e.ToString()); return false; } } return true; }
private static bool AddLessonsToCourse(LESSON[] lessons, COURSE course) { using (CloudEDUEntities ctx = new CloudEDUEntities()) { try { var cs = ctx.COURSEs.Include("LESSONs").Where(c => c.ID == course.ID).FirstOrDefault(); foreach (LESSON ls in lessons) cs.LESSONs.Add(ls); ctx.Entry(cs).State = System.Data.EntityState.Modified; ctx.SaveChanges(); } catch (Exception e) { System.Diagnostics.Debug.WriteLine(e.ToString()); return false; } } return true; }
/// <summary> /// 用于更改课程信息,这是一个很强的方法,理论上可以更改全部信息。该方法可以覆盖UpdateCourseStatus的功能。 /// 如果有更相应的方法不推荐使用这个方法 /// </summary> /// <param name="course">更改后的Course的实例</param> /// <returns>ture表示成功,false表示失败</returns> public static bool UpdateCourse(COURSE course) { using (CloudEDUEntities ctx = new CloudEDUEntities()) { try { ctx.Entry(course).State = System.Data.EntityState.Modified; ctx.SaveChanges(); } catch (Exception e) { System.Diagnostics.Debug.WriteLine(e.ToString()); return false; } } return true; }
public static bool RemoveCourseFromRecommendation(COURSE course, RECOMMENDATION reco) { using (CloudEDUEntities ctx = new CloudEDUEntities()) { try { ctx.RECOMMENDATIONs.Attach(reco); ctx.COURSEs.Attach(course); reco.COURSEs.Remove(course); ctx.SaveChanges(); } catch (Exception e) { System.Diagnostics.Debug.WriteLine(e.ToString()); return false; } } return true; }
public static LESSON[] GetLessonsByCourse(COURSE course) { LESSON[] lessons = null; using (CloudEDUEntities ctx = new CloudEDUEntities()) { var cs = ctx.COURSEs.Include("LESSONs").Where(c => c.ID == course.ID).FirstOrDefault(); lessons = cs.LESSONs.ToArray(); } return lessons; }
public static COMMENT[] GetCommentsByCourse(COURSE course) { COMMENT[] comments = null; using (CloudEDUEntities ctx = new CloudEDUEntities()) { comments = ctx.COMMENTs.Where(c => c.COURSE_ID == course.ID).ToArray(); } return comments; }
public static COURSE[] GetAllPendingCourses() { COURSE_PENDING[] courses = null; using (CloudEDUEntities ctx = new CloudEDUEntities()) { courses = ctx.COURSE_PENDING.ToArray(); } COURSE[] returnCourse=new COURSE[courses.Length]; for (int i = 0; i < courses.Length; i++) { returnCourse[i] = ConvertToCourse(courses[i]); } return returnCourse; }