public ActionResult AddGrade(int id)
        {
            List<CourseEnrollment> CourseStudents =
                (from c in db.CourseEnrollment
                 where c.Course.id == id && c.Grade == 0
                 select c).ToList();

            if (CourseStudents != null)
            {
                ViewData["CourseStudents"] = new SelectList(CourseStudents, "Course", "id");
            }
            else
            {

                ViewData["CourseStudents"] = new SelectList(new List<CourseEnrollment>());
                ViewData["CourseStudent"] = new CourseEnrollment();
            }

            String s = " ";
            ViewData["Grade"] = s.ToString();
            return PartialView("_ShowGrades");
        }
 public ActionResult Enroll(int id)
 {
     Course course = db.Courses.Find(id);
     User user =
            (from u in db.Users
             where u.userName == User.Identity.Name
             select u).SingleOrDefault();
     if (user != null)
     {
         CourseEnrollment enrollment = new CourseEnrollment();
         enrollment.User = user;
         enrollment.Course = course;
         course.courseEnrollments.Add(enrollment);
         db.CourseEnrollment.Add(enrollment);
         db.SaveChanges();
     }
     return RedirectToAction("Details", new { id = id });
 }
 public void saveGrade(int grade, CourseEnrollment courseEnrollment)
 {
     if (courseEnrollment != null)
     {
         courseEnrollment.Grade = grade;
         db.SaveChanges();
     }
 }
 //
 // GET: /Course/Details/5
 public ViewResult Details(int id)
 {
     ViewData["CourseStudents"] = new SelectList(new List<CourseEnrollment>());
     ViewData["Course"] = new CourseEnrollment();
     Course course = db.Courses.Find(id);
     List<CourseEnrollment> enrollments =
         (from ce in db.CourseEnrollment
          where ce.Course.id == id
          && ce.User.userName == User.Identity.Name
          select ce).ToList();
     //Simo on f*g
     List<FileUpload> files =
         (from file in db.Files
          where file.course.id == id
          select file).ToList();
     course.files = files;
     ViewBag.Enrolled = enrollments.Count > 0;
     ViewBag.CourseId = id;
     return View(course);
 }