public ActionResult Create(Enrollment enrollment)
        {
            Student student = db.StudentDbSet.Find(enrollment.StudentID);
            ViewBag.Name = student.StudentName;
            ViewBag.Email = student.Email;
            ViewBag.Dept = student.Department.DeptName;
            if (ModelState.IsValid)
            {
                Enrollment testEnrollment
                    = db.EnrollmentDbSet.FirstOrDefault(
                        e => (e.StudentID == enrollment.StudentID) && (e.CourseID == enrollment.CourseID));

                Course course
                    = db.CourseDbSet.Find(enrollment.CourseID);
                if (testEnrollment==null)
                {
                    enrollment.GradeID = 1;
                    db.EnrollmentDbSet.Add(enrollment);
                    if (db.SaveChanges() > 0)
                        ViewBag.Message = "This Course : " + course.CourseCode + " has been successfully Enrolled to student " + student.StudentName;
                    ViewBag.StudentID = new SelectList(db.StudentDbSet, "StudentID", "RegNo", enrollment.StudentID);
                    ViewBag.CourseID = new SelectList(db.CourseDbSet, "CourseID", "CourseCode", enrollment.CourseID);
                    ViewBag.GradeID = new SelectList(db.GradeDbSet, "GradeID", "GradeLetter", enrollment.GradeID);
                    return View(enrollment);
                }
                else
                {
                    ViewBag.Message = "This Course : " + course.CourseCode + " is already Enrolled to student " + student.StudentName;
                    ViewBag.StudentID = new SelectList(db.StudentDbSet, "StudentID", "RegNo", enrollment.StudentID);
                    ViewBag.CourseID = new SelectList(db.CourseDbSet, "CourseID", "CourseCode", enrollment.CourseID);
                    ViewBag.GradeID = new SelectList(db.GradeDbSet, "GradeID", "GradeLetter", enrollment.GradeID);
                    return View(enrollment);
                }

            }

            ViewBag.StudentID = new SelectList(db.StudentDbSet, "StudentID", "RegNo", enrollment.StudentID);
            ViewBag.CourseID = new SelectList(db.CourseDbSet, "CourseID", "CourseCode", enrollment.CourseID);
            ViewBag.GradeID = new SelectList(db.GradeDbSet, "GradeID", "GradeLetter", enrollment.GradeID);
            return View(enrollment);
        }
        public ActionResult ResultEntry(Enrollment enrollment)
        {
            if (ModelState.IsValid)
            {
                Enrollment anEnrollment = db.EnrollmentDbSet.FirstOrDefault(e=>(e.CourseID==enrollment.CourseID)&&(e.StudentID==enrollment.StudentID));
                Student student
                    = db.StudentDbSet.Find(enrollment.StudentID);
                Course course
                    = db.CourseDbSet.Find(enrollment.CourseID);
                if (anEnrollment.GradeID == 1)
                {
                    anEnrollment.GradeID = enrollment.GradeID;
                    if (db.SaveChanges() > 0)
                        ViewBag.Message = "Result For This Course : " + course.CourseCode +
                                          " has been successfully Entered For student " + student.StudentName;
                    ViewBag.StudentID = new SelectList(db.StudentDbSet, "StudentID", "RegNo");
                    ViewBag.CourseID = new SelectList("", "CourseID", "CourseCode");
                    ViewBag.GradeID = new SelectList(db.GradeDbSet.Where(g => g.GradeID != 1), "GradeID", "GradeLetter");
                    return View();
                }

                ViewBag.Message = "Result For This Course : " + course.CourseCode
                    + " has already been published For student " + student.StudentName;
                ViewBag.StudentID = new SelectList(db.StudentDbSet, "StudentID", "RegNo");
                ViewBag.CourseID = new SelectList("", "CourseID", "CourseCode");
                ViewBag.GradeID = new SelectList(db.GradeDbSet.Where(g => g.GradeID != 1), "GradeID", "GradeLetter");
                return View();

            }
            ViewBag.StudentID = new SelectList(db.StudentDbSet, "StudentID", "RegNo");
            ViewBag.CourseID = new SelectList("", "CourseID", "CourseCode");
            ViewBag.GradeID = new SelectList(db.GradeDbSet.Where(g => g.GradeID != 1), "GradeID", "GradeLetter");
            return View();
        }
 public ActionResult Edit(Enrollment enrollment)
 {
     if (ModelState.IsValid)
     {
         db.Entry(enrollment).State = EntityState.Modified;
         db.SaveChanges();
         return RedirectToAction("Index");
     }
     ViewBag.StudentID = new SelectList(db.StudentDbSet, "StudentID", "RegNo", enrollment.StudentID);
     ViewBag.CourseID = new SelectList(db.CourseDbSet, "CourseID", "CourseCode", enrollment.CourseID);
     ViewBag.GradeID = new SelectList(db.GradeDbSet, "GradeID", "GradeLetter", enrollment.GradeID);
     return View(enrollment);
 }