public ActionResult Create(Course course) { if (ModelState.IsValid) { Request<Course>.Add(course, "A", "B"); return RedirectToAction("Index"); } return View(course); }
public void CourseHoursCalculatesVariableProperly() { Course course = new Course() { minHours = 1, maxHours = 1, variable = true }; Assert.AreEqual("Variable", course.courseHours); }
public void CourseHoursCalculatesSingleHoursProperly() { Course course = new Course() { minHours = 1, maxHours = 1, variable = false }; Assert.AreEqual("1", course.courseHours); }
public void CourseHeaderFormattedProperly() { Course course = new Course(){ courseNumber = 101, coursePrefix = "ABCDE", courseTitle = "Lorem Ipsum Title Test" }; String courseHeader = course.coursePrefix + " " + course.courseNumber + " - " + course.courseTitle; Assert.AreEqual(courseHeader, course.courseHeader); }
public void CourseCatalogNumberFormattedProperly() { Course course = new Course() { courseNumber = 101, coursePrefix = "ABCDE", }; String courseCatalogNumber = course.coursePrefix + " " + course.courseNumber; Assert.AreEqual(courseCatalogNumber, course.courseCatalogNumber); }
private Course createTempCourse() { Course temp = new Course() { ID = 4, courseNumber = 789, coursePrefix = "CCC", courseTitle = "Test Created Course", courseDescription = "Created Course for testing Methods", minHours = 3, maxHours = 4 }; return temp; }
public ActionResult Edit(Course course, IEnumerable<PrerequisiteCourse> PrerequisiteCourses) { if (ModelState.IsValid) { Course cAttached = Request<Course>.GetItemByID(course.ID, "A", "B"); course.prerequisites = cAttached.prerequisites; if (PrerequisiteCourses == null) { PrerequisiteCourses = new List<PrerequisiteCourse>(); } if (course.prerequisites == null) { course.prerequisites = new List<PrerequisiteCourse>(); } //figure out the courses that were removed from the list LinkedList<PrerequisiteCourse> toRemove = new LinkedList<PrerequisiteCourse>(); foreach (PrerequisiteCourse pcourse in course.prerequisites) { if (course.ID > 0) { if (!PrerequisiteCourses.Contains(pcourse)) { PrerequisiteCourse elcourseAttached = Request<PrerequisiteCourse>.GetItemByID(pcourse.ID, "A", "B"); toRemove.AddFirst(elcourseAttached); } } } //remove those courses from the database while (toRemove.Count > 0) { PrerequisiteCourse removeme = toRemove.First(); toRemove.RemoveFirst(); Request<PrerequisiteCourse>.Delete(removeme.ID, "A", "B"); } //clear the list todo course.prerequisites = new List<PrerequisiteCourse>(); //add the existing courses to the database foreach (PrerequisiteCourse pcourse in PrerequisiteCourses) { PrerequisiteCourse pcourseAttached = null; ; if (pcourse.ID > 0) { pcourseAttached = Request<PrerequisiteCourse>.GetItemByID(pcourse.ID, "A", "B"); Request<PrerequisiteCourse>.Update(pcourseAttached, pcourse, "A", "B"); } else { if (Request<Course>.GetItemByID(pcourse.prerequisiteCourseID, "A", "B") != null) { int id = Request<PrerequisiteCourse>.Add(pcourse, "A", "B"); pcourseAttached = Request<PrerequisiteCourse>.GetItemByID(id, "A", "B"); } } if (pcourseAttached != null) { course.prerequisites.Add(pcourseAttached); } } Request<Course>.Update(cAttached, course, "A", "B"); return RedirectToAction("Index"); } if (PrerequisiteCourses != null) { foreach (PrerequisiteCourse pcourse in PrerequisiteCourses) { if (pcourse.prerequisiteCourseID> 0) { pcourse.prerequisiteCourse = Request<Course>.GetItemByID(pcourse.prerequisiteCourseID, "A", "B"); } } } course.prerequisites = PrerequisiteCourses.ToList(); return View(course); }