public ActionResult Create(CreateStudentAccountVM studentInfo)
        {
            if (ModelState.IsValid)
            {
                var student = new Student
                {
                    FirstName   = studentInfo.FirstName,
                    LastName    = studentInfo.LastName,
                    Email       = studentInfo.Email,
                    UserName    = studentInfo.Email,
                    CourseId    = studentInfo.CourseId,
                    PhoneNumber = studentInfo.PhoneNumber,
                    LastLogon   = new DateTime(1970, 1, 1)
                };

                // Student inherits from ApplicationUser,  so the UserManager should accept it.
                var result = UserManager.Create(student as ApplicationUser, studentInfo.Password);
                if (result.Succeeded)
                {
                    result = UserManager.AddToRole(student.Id, "Student");
                }
                db.SaveChanges();
                TempData["Message"] = "Student Account created.";
                if (studentInfo.ReturnToIndex == true)
                {
                    return(RedirectToAction("Index"));
                }
                return(RedirectToAction("Manage", "Courses", new { id = student.CourseId }));
            }
            studentInfo.Courses = db.Courses.Select(c => new SelectListItem {
                Value = c.Id.ToString(), Text = c.Name
            }).ToList();
            return(View(studentInfo));
        }
        public ActionResult Create(int?courseId)
        {
            var vm = new CreateStudentAccountVM
            {
                Courses = db.Courses.Select(x => new SelectListItem
                {
                    Value = x.Id.ToString(),
                    Text  = x.Name
                })
            };

            if (courseId != null)
            {
                vm.CourseId = courseId.GetValueOrDefault();
            }
            else
            {
                /* This was invoked from the Students list, so we should return there.*/
                vm.ReturnToIndex = true;
            }
            return(View(vm));
        }