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");
}