//Constructor for new course. public CourseWindow(tblCours course, int newestCourseID) : this() { courseViewModel = new CourseViewModel(course, newestCourseID); this.DataContext = courseViewModel; this.Title = "New course :"; labelHeader.Content = "Please enter the following information to create a new Course."; }
public CourseViewModel(tblCours course) : this() { if (course != null) { Course = course; } }
/// <summary> /// This function removes the selected class from the database. /// </summary> public void RemoveClass() { //Get the course we want to remove. course = selectedCourseList; //Display message to confirm action. switch (MessageBox.Show( String.Format("This will remove the course {0}. Are you sure you want to remove this course?", course.name), "WARNING: Are you sure you want to remove the course?", MessageBoxButton.YesNo, MessageBoxImage.Question)) { case MessageBoxResult.Yes: using (RegistarDbContext db = new RegistarDbContext()) { var classList = db.tblCourses .Where(id => id.courseID == course.courseID) .Select(c => c).FirstOrDefault(); db.tblCourses.Remove(classList); db.SaveChanges(); } break; case MessageBoxResult.No: break; } }
//Constructor for editing course public CourseWindow(tblCours course) : this() { courseViewModel = new CourseViewModel(course); this.DataContext = courseViewModel; this.Title = "Edit course :"; labelHeader.Content = "Editing course " + course.name; }
public ActionResult DeleteConfirmed(int id) { tblCours tblCours = db.tblCourses.Find(id); db.tblCourses.Remove(tblCours); db.SaveChanges(); return(RedirectToAction("Index")); }
public void ChecktblCours() { tblCours cours = new tblCours(); cours.name = "Mathematics"; Assert.IsNotNull(cours); Assert.AreEqual("Mathematics", cours.name); }
public ActionResult Edit([Bind(Include = "id,name,description,active,icon")] tblCours tblCours) { if (ModelState.IsValid) { db.Entry(tblCours).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(tblCours)); }
public ActionResult Create([Bind(Include = "id,name,description,active,icon")] tblCours tblCours) { if (ModelState.IsValid) { db.tblCourses.Add(tblCours); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(tblCours)); }
/// <summary> /// Takes the course and student /// Then loops threw each student in the selected class /// returns true if the student already exists /// </summary> /// <param name="cours">The selected course from the dropdown list</param> /// <param name="student">The selected student from the dropdown list</param> /// <returns></returns> public bool checkIfExists(tblCours cours, tblStudent student) { foreach (var item in cours.tblStudents) { if (item.studentID == student.studentID) { return(true); } } return(false); }
// GET: tblCours/Delete/5 public ActionResult Delete(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } tblCours tblCours = db.tblCourses.Find(id); if (tblCours == null) { return(HttpNotFound()); } return(View(tblCours)); }
public void Save(tblCours newCourse) { using (RegistarDbContext db = new RegistarDbContext()) { //Add new newest course ID to the course. if (newCourse.courseID == 0) { newCourse.courseID = NewestCourseID; } db.tblCourses.Add(newCourse); db.SaveChanges(); } }
/// <summary> /// This function gets the student that you've selected in the class list, /// Then removes it. /// </summary> public void RemoveSelectedStudent() { //Get the course that we want to remove from. course = selectedCourseList; using (RegistarDbContext db = new RegistarDbContext()) { //Get the class list. var classList = db.tblCourses.Where(c => c.courseID == course.courseID).FirstOrDefault(); //Get the student infromation from the database. var studentToRemove = db.tblStudents.Where(s => s.studentID == selectedStudentsInClass.studentID).FirstOrDefault(); //Remove the selected student. classList.tblStudents.Remove(studentToRemove); db.SaveChanges(); MessageBox.Show(String.Format("{0} was removed successfully!", studentToRemove.fullName), "Student successfully removed", MessageBoxButton.OK, MessageBoxImage.Information); } }
/// <summary> /// This function prompts you with a messagebox that as if you want to remove all the students from the list, /// It then removes each student. /// </summary> public void DeleteAll() { //Get the course that we want to remove. course = selectedCourseList; //Display message to confirm action. switch (MessageBox.Show( String.Format("This will remove all the students from {0}. Are you sure you want to perform this action?", course.name), "WARNING: Are you sure you want to clear the class list?", MessageBoxButton.YesNo, MessageBoxImage.Warning)) { case MessageBoxResult.Yes: using (RegistarDbContext db = new RegistarDbContext()) { //Select all the classes with the course ID. var classList = db.tblCourses.Where(c => c.courseID == course.courseID).FirstOrDefault(); //Select all the students you want to delete. var studentsInClass = db.tblCourses .Where(n => n.courseID == course.courseID) .SelectMany(s => s.tblStudents); //For each of the students that we want to delete: foreach (var item in studentsInClass) { //Remove it from the student list in the coresponding course list. classList.tblStudents.Remove(item); } db.SaveChanges(); MessageBox.Show(String.Format("{0} was cleared successfully!", course.name), "Course successfully cleared", MessageBoxButton.OK, MessageBoxImage.Information); } break; case MessageBoxResult.No: break; } }
public CourseViewModel(tblCours course, int newestCourseID) : this() { Course = course; NewestCourseID = newestCourseID; }
private void btnSave_Click(object sender, RoutedEventArgs e) { Course = (tblCours)this.DataContext; courseViewModel.Save(Course); }