public ActionResult Create(Student aStudent,Course aCourse,DateTime date)
        {
            Create();
            if (aStudent.StudentId == 0 || aCourse.CourseId == 0)
            {
                ViewBag.ErrorMessage = "All fields are required.";
                return View();
            }
            Enrollment enrollment = new Enrollment();
            enrollment.StudentId = aStudent.StudentId;
            enrollment.CourseId = aCourse.CourseId;
            enrollment.Date = date;
            Student student = (db.Students.Where(s => s.StudentId == aStudent.StudentId)).Single();
            Course course = db.Courses.Single(c => c.CourseId == aCourse.CourseId);
            bool check = db.Enrollments.Count(c => c.StudentId == aStudent.StudentId && c.CourseId == aCourse.CourseId) == 0;
            if (check)
            {
                db.Enrollments.Add(enrollment);
                db.SaveChanges();
                ViewBag.Message = course.Code + " has assigned for " + student.RegNo;
                return View(enrollment);
            }

            enrollment.Student = student;
            enrollment.Course = course;
            ViewBag.ErrorMessage = student.RegNo+" has already enrolled for "+course.Code;
            return View(enrollment);
        }
        public ActionResult Create(Student student)
        {
            ViewBag.DepartmentId = new SelectList(db.Departments, "DepartmentId", "Code", student.DepartmentId);
            if (ModelState.IsValid)
            {
                int count = db.Students.Count(s => s.DepartmentId == student.DepartmentId & s.Date.Year == student.Date.Year);
                //student.RegNo = "OOP0140" + (count+1);
                Department department = db.Departments.Find(student.DepartmentId);
                student.RegNo = department.Code + DateTime.Now.Year + (count + 1).ToString("D3");
                db.Students.Add(student);
                db.SaveChanges();
                ViewBag.Message = student.Name + "'s registration number is " + student.RegNo;
                return View();
            }

            return View(student);
        }
 public ActionResult Edit(Student student)
 {
     if (ModelState.IsValid)
     {
         db.Entry(student).State = EntityState.Modified;
         db.SaveChanges();
         return RedirectToAction("Index");
     }
     ViewBag.DepartmentId = new SelectList(db.Departments, "DepartmentId", "Code", student.DepartmentId);
     return View(student);
 }