public void CanAssCourse() { provider = new CourseProvider(); // DaysOfWeek = "MWF" var course = new Course { CourseName = "CSTest", Monday = true, Friday = true, StartHour = 13, StartMinute = 0, EndHour = 14, EndMinute = 15, AssignedProfessor = null }; var newIdentity = provider.AddCourse(course); var testCourse = provider.GetCourseByID(newIdentity); Assert.Equal(testCourse.EndHour, 14); }
public object Edit([Bind(Prefix = "")] Course course, string id, string ProfessorList) { ViewData["Title"] = "Edit Course"; ViewData["Message"] = "Edit Course Details!"; var cp = new CourseProvider(); int courseId; try { courseId = Convert.ToInt32(id); } catch (Exception) //not an integer { return RedirectToAction("Index", "Course"); } course = cp.GetCourseByID(courseId); // redisplay form immediately if there are input format errors if (!ModelState.IsValid) { ModelState.CopyValidationExceptions(); PrepareProfessorList(course); return View("Edit", course); } try { UpdateModel(course, new[] { "CourseName", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday", "StartHour", "StartMinute", "EndHour", "EndMinute"}); if (!ProfessorList.Equals("0")) { Professor prof = new ProfessorProvider().GetProfessorByID(Convert.ToInt32(ProfessorList)); course.AssignedProfessor = prof; } else { course.AssignedProfessor = null; } cp.UpdateCourse(course); return View("Saved"); } catch (RuleViolationException vex) { ViewData.ModelState.CopyValidationExceptions(vex); PrepareProfessorList(course); return View(course); } catch (Exception err) { ViewData.ModelState.CopyValidationExceptions(err, "course"); PrepareProfessorList(course); return View(course); } }
public ActionResult Delete(string id) { var cp = new CourseProvider(); if (!string.IsNullOrEmpty(id)) { int courseId; try { courseId = Convert.ToInt32(id); } catch (Exception) //not an integer { return RedirectToAction("Index", "Course"); } try { Course course = cp.GetCourseByID(courseId); if (course != null) { cp.DeleteCourse(course); return View("Deleted"); } return RedirectToAction("Index"); } catch (Exception err) { if (err.InnerException != null && err.InnerException.Message.Contains("The DELETE statement conflicted with the REFERENCE constraint")) { ViewData["ErrorMessage"] = "Course could not be deleted.. there are assoiciated data.. cannot delete"; } else { ViewData["ErrorMessage"] = "Course Could not be deleted.. there is a problem"; } return View("NotDeleted"); } } return RedirectToAction("Index"); }