public ActionResult Register(StudentViewModel model) { if (ModelState.IsValid) { // Attempt to register the user try { cog.WebSecurity.CreateUserAndAccount(model.UserName, model.Password); if (cog.WebSecurity.Login(model.UserName, model.Password)) { var currentuserid = cog.WebSecurity.GetUserId(model.UserName); if (_studentService.CreateStudentUser(currentuserid, model)) { //Send email to register user. SendRegisterEmail(model); } } return(RedirectToAction("Index", "Student")); } catch (MembershipCreateUserException e) { ModelState.AddModelError("", ErrorCodeToString(e.StatusCode)); } } // If we got this far, something failed, redisplay form ViewBag.GenderTypes = _typeService.GetAllGenderTypes(); return(View(model)); }