public async Task <ActionResult> Register(RegisterViewModel model) { if (ModelState.IsValid) { var user = new ApplicationUser { UserName = model.Email, Email = model.Email }; var result = await UserManager.CreateAsync(user, model.Password); if (result.Succeeded) { await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false); // For more information on how to enable account confirmation and password reset please visit https://go.microsoft.com/fwlink/?LinkID=320771 // Send an email with this link // string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id); // var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme); // await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>"); AspNetUserRole aspNetUserRole = new AspNetUserRole(); aspNetUserRole.UserId = user.Id; aspNetUserRole.RoleId = "100"; role.AspNetUserRoles.Add(aspNetUserRole); role.SaveChanges(); PatientModel pm = new PatientModel(); Patient patient = new Patient(); patient.FirstName = model.FirstName; patient.LastName = model.LasttName; patient.Id = user.Id; patient.EmailId = model.Email; patient.patientId = r.Next(0, 1000); patient.DOB = model.Dob; patient.SuburbId = Int32.Parse(model.Suburb); pm.Patients.Add(patient); pm.SaveChanges(); return(RedirectToAction("Index", "Home")); } AddErrors(result); } ViewBag.Location = (from item in mindSpot.locations.ToList() select new SelectListItem { Text = item.suburb, Value = item.Id.ToString() }); // If we got this far, something failed, redisplay form return(View(model)); }