public async Task <ActionResult> Register(RegisterViewModel model) { using (var context = new ApplicationDbContext()) { if (model.Rodo == false) { return(View(model)); } if (ModelState.IsValid) { var user = new ApplicationUser() { UserName = model.Email, Email = model.Email }; var result = await UserManager.CreateAsync(user, model.Password); var roleStore = new RoleStore <IdentityRole>(context); var roleManager = new RoleManager <IdentityRole>(roleStore); var userStore = new UserStore <ApplicationUser>(context); var userManager = new UserManager <ApplicationUser>(userStore); // userManager.AddToRole(user.Id, "User"); if (result.Succeeded) { // TO DO dodanie nowego user profile, context wziac z profiles controller Profile userProfile = new Profile(user.Email); WetContext db = new WetContext(); db.Profiles.Add(userProfile); db.SaveChanges(); userManager.AddToRole(user.Id, "User"); string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id); var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme); SendMail(user.Email, "Dziękujemy za założenie konta na naszym portalu aby potwierdzić email wejdź w ten link " + callbackUrl, " Powiadomienie z gabinetu Gab wet"); await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false); return(RedirectToAction("Edit", "Profiles", new { id = userProfile.ID })); } AddErrors(result); } } // If we got this far, something failed, redisplay form return(View(model)); }