public ActionResult Create(ResultEntry resultentry)
        {
            if (ModelState.IsValid)
            {
                var result =
                    db.ResultEntries.Count(
                        r => r.StudentId == resultentry.StudentId && r.CourseId == resultentry.CourseId) == 0;
                if (result)
                {
                    Grade aGrade = db.Grades.Where(g => g.GradeId == resultentry.GradeId).FirstOrDefault();
                    EnrollCourse resultEnrollCourse =
                        db.EnrollCourses.FirstOrDefault(r => r.CourseId == resultentry.CourseId && r.StudentId == resultentry.StudentId);

                    if (resultEnrollCourse != null) resultEnrollCourse.GradeName = aGrade.Name;

                    db.ResultEntries.Add(resultentry);
                    db.SaveChanges();
                    TempData["success"] = "Result Successfully Entered";
                    return RedirectToAction("Create");
                }
                else
                {
                    TempData["Already"] = "Result Of This Course has Already Been Assigned";
                    return RedirectToAction("Create");
                }
            }

            ViewBag.StudentId = new SelectList(db.Students, "StudentId", "RegistrationId", resultentry.StudentId);
            ViewBag.CourseId = new SelectList(db.Courses, "CourseId", "Code", resultentry.CourseId);
            ViewBag.GradeId = new SelectList(db.Grades, "GradeId", "Name", resultentry.GradeId);
            return View(resultentry);
        }
 public ActionResult Edit(ResultEntry resultentry)
 {
     if (ModelState.IsValid)
     {
         db.Entry(resultentry).State = EntityState.Modified;
         db.SaveChanges();
         return RedirectToAction("Index");
     }
     ViewBag.StudentId = new SelectList(db.Students, "StudentId", "RegistrationId", resultentry.StudentId);
     ViewBag.CourseId = new SelectList(db.Courses, "CourseId", "Code", resultentry.CourseId);
     ViewBag.GradeId = new SelectList(db.Grades, "GradeId", "Name", resultentry.GradeId);
     return View(resultentry);
 }