partial void DeleteCourseCancelled(CourseCancelled instance);
partial void InsertCourseCancelled(CourseCancelled instance);
partial void UpdateCourseCancelled(CourseCancelled instance);
/// <summary> /// This loads cancelled classes from a feed and sends emails to registered students. /// </summary> public static void LoadStream() { XElement cancel = XElement.Load(FEED); var test = from t in cancel.Descendants("item") select t.Element("title").Value; if(!test.FirstOrDefault().Equals("No classes cancelled.")) { IEnumerable<CancelledClass> classes = from c in cancel.Descendants("item") select new CancelledClass(c.Element("title").Value, c.Element("course").Value, c.Element("datecancelled").Value, c.Element("teacher").Value, c.Element("notes").Value); List<CancelledClass> newCancelled = new List<CancelledClass>(); bool isNew = true; using (TablesDataContext db = new TablesDataContext()) { IEnumerable<CancelledClass> allCancelled = from c in db.CourseCancelleds select new CancelledClass(c.CourseID, c.Title, c.DateCancelled, c.Teacher, c.Notes); string previousCourseID = ""; string previousDateCancelled = ""; foreach (CancelledClass c in classes) { isNew = true; if (c.CourseID.Equals(previousCourseID) && c.DateCancelled.Equals(previousDateCancelled)) isNew = false; else foreach (CancelledClass allC in allCancelled) { if(c.Equals(allC)) { isNew = false; break; } } if (isNew) newCancelled.Add(c); previousCourseID = c.CourseID; previousDateCancelled = c.DateCancelled; } //Add the new cancelled courses to the database CourseCancelled course; foreach (CancelledClass c in newCancelled) { course = new CourseCancelled(); course.CourseID = c.CourseID; course.DateCancelled = c.DateCancelled; course.Teacher = c.Teacher; course.Notes = c.Notes; course.Title = c.Title; db.CourseCancelleds.InsertOnSubmit(course); //Cycle through new cancellations and send emails. var students = from s in db.StudentCourses where s.CourseID.Equals(c.CourseID) select s.StudentID; foreach (int studentID in students) { //Select email, send email. var listOfEmails = from s in db.Students where s.StudentID == studentID select s.Email; string email = listOfEmails.FirstOrDefault(); sendEmail(email, c); } } try { db.SubmitChanges(); } catch (ChangeConflictException cce) { foreach (var conflict in db.ChangeConflicts) conflict.Resolve(RefreshMode.KeepCurrentValues); db.SubmitChanges(); } }//end of using } }
/// <summary> /// This loads cancelled classes from a feed and sends emails to registered students. /// </summary> public static void LoadStream() { XElement cancel = XElement.Load(FEED); var test = from t in cancel.Descendants("item") select t.Element("title").Value; if (!test.FirstOrDefault().Equals("No classes cancelled.")) { IEnumerable <CancelledClass> classes = from c in cancel.Descendants("item") select new CancelledClass(c.Element("title").Value, c.Element("course").Value, c.Element("datecancelled").Value, c.Element("teacher").Value, c.Element("notes").Value); List <CancelledClass> newCancelled = new List <CancelledClass>(); bool isNew = true; using (TablesDataContext db = new TablesDataContext()) { IEnumerable <CancelledClass> allCancelled = from c in db.CourseCancelleds select new CancelledClass(c.CourseID, c.Title, c.DateCancelled, c.Teacher, c.Notes); string previousCourseID = ""; string previousDateCancelled = ""; foreach (CancelledClass c in classes) { isNew = true; if (c.CourseID.Equals(previousCourseID) && c.DateCancelled.Equals(previousDateCancelled)) { isNew = false; } else { foreach (CancelledClass allC in allCancelled) { if (c.Equals(allC)) { isNew = false; break; } } } if (isNew) { newCancelled.Add(c); } previousCourseID = c.CourseID; previousDateCancelled = c.DateCancelled; } //Add the new cancelled courses to the database CourseCancelled course; foreach (CancelledClass c in newCancelled) { course = new CourseCancelled(); course.CourseID = c.CourseID; course.DateCancelled = c.DateCancelled; course.Teacher = c.Teacher; course.Notes = c.Notes; course.Title = c.Title; db.CourseCancelleds.InsertOnSubmit(course); //Cycle through new cancellations and send emails. var students = from s in db.StudentCourses where s.CourseID.Equals(c.CourseID) select s.StudentID; foreach (int studentID in students) { //Select email, send email. var listOfEmails = from s in db.Students where s.StudentID == studentID select s.Email; string email = listOfEmails.FirstOrDefault(); sendEmail(email, c); } } try { db.SubmitChanges(); } catch (ChangeConflictException cce) { foreach (var conflict in db.ChangeConflicts) { conflict.Resolve(RefreshMode.KeepCurrentValues); } db.SubmitChanges(); } } //end of using } } //end of method