public static bool AddRecommendation(RECOMMENDATION reco) { using (CloudEDUEntities ctx = new CloudEDUEntities()) { try { ctx.Set<RECOMMENDATION>().Add(reco); ctx.SaveChanges(); } catch (Exception e) { System.Diagnostics.Debug.WriteLine(e.ToString()); return false; } } return true; }
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; }
public static bool UpdateRecommendation(RECOMMENDATION reco) { using (CloudEDUEntities ctx = new CloudEDUEntities()) { try { ctx.Entry(reco).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 COURSE[] GetCoursesByRecommendation(RECOMMENDATION reco) { COURSE[] courses = null; using (CloudEDUEntities ctx = new CloudEDUEntities()) { var rc = ctx.RECOMMENDATIONs.Include("COURSEs").Where(r => r.ID == reco.ID).FirstOrDefault(); courses = rc.COURSEs.ToArray(); } return courses; }