public object Create([Bind(Prefix = "")]Course course, string ProfessorList)
{
ViewData["Title"] = "Create Course";
ViewData["Message"] = "Create a Course";
//To DO
//UpdateModel(course); // to do
// redisplay form immediately if there are input format errors
if (!ModelState.IsValid)
{
ModelState.CopyValidationExceptions();
PrepareProfessorList(course);
return View("Create", course);
}
try
{
if (ProfessorList != null)
if (!ProfessorList.Equals("0"))
{
var profp = new ProfessorProvider();
Professor prof = profp.GetProfessorByID(Convert.ToInt32(ProfessorList));
course.AssignedProfessor = prof;
}
new CourseProvider().AddCourse(course);
ViewData["Message"] = "Course created";
return View("Saved");
}
catch (RuleViolationException vex)
{
ViewData.ModelState.CopyValidationExceptions(vex);
PrepareProfessorList(course);
return View("Create", course);
}
catch (Exception err)
{
ViewData.ModelState.CopyValidationExceptions(err, "course");
PrepareProfessorList(course);
return View("Create");
}
}