public ActionResult SetupMembershipWebAccount(MembershipAccountViewModel membershipAccountViewModel) { if (!String.IsNullOrWhiteSpace(membershipAccountViewModel.VerifiedEmail)) { MembershipAccountLoginSetupViewModel membershipAccountLoginSetupViewModel = new MembershipAccountLoginSetupViewModel(); membershipAccountLoginSetupViewModel.Email = membershipAccountViewModel.VerifiedEmail; membershipAccountLoginSetupViewModel.PersonPrimaryInfoID = membershipAccountViewModel.PersonPrimaryInfo.PersonPrimaryInfoID; membershipAccountLoginSetupViewModel.Password = "******"; return RedirectToAction("SendNewWebAccountEmail", "Account", membershipAccountLoginSetupViewModel); } return RedirectToAction("Index", new { personPrimaryInfoID = membershipAccountViewModel .PersonPrimaryInfo.PersonPrimaryInfoID}); }
public async Task<ActionResult> SendNewWebAccountEmail(MembershipAccountLoginSetupViewModel model) { var user = new ApplicationUser { UserName = model.Email, Email = model.Email }; var resultFromAccountCreation = await UserManager.CreateAsync(user, model.Password); string callbackUrl = null; if (resultFromAccountCreation.Succeeded) { var emailCode = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id); var resultFromEmailConfirmation = await UserManager.ConfirmEmailAsync(user.Id, emailCode); var resultFromAddingMembershipRole = await UserManager.AddToRolesAsync(user.Id, AppRole.ActiveMember.ToString()); if (resultFromAddingMembershipRole.Succeeded) { using (UnitOfWork unitOfWork = new UnitOfWork(new ChurchManagerEntities())) { //Assign web account to a user unitOfWork.context.Database.ExecuteSqlCommand(@" UPDATE [dbo].[AspNetUsers] SET [PersonPrimaryInfoID] = @PersonPrimaryInfoID WHERE [Id] = @UserID ", new SqlParameter("@UserID", user.Id), new SqlParameter("@PersonPrimaryInfoID", model.PersonPrimaryInfoID)); //Prompt user account Update unitOfWork.context.Database.ExecuteSqlCommand(@" UPDATE [dbo].[PersonPrimaryInfo] SET [PromptContactInformationUpdate] = 1 WHERE PersonPrimaryInfoID = @PersonPrimaryInfoID ", new SqlParameter("@PersonPrimaryInfoID", model.PersonPrimaryInfoID)); } } //string code = UserManager.GeneratePasswordResetToken<ApplicationUser, string>(user.Id); //callbackUrl = Url.Action("ResetPassword", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme); ////if (HttpContext.Request.IsLocal) ////{ //// MandrillMailer mandrillMailer = new MandrillMailer(); //// mandrillMailer.SendNewMembershipAccountCreation(user.Email, callbackUrl); ////} //MandrillMailer mandrillMailer = new MandrillMailer(); //mandrillMailer.SendNewMembershipAccountCreation(user.Email, callbackUrl); //TempData["SuccessAlertCustom"] = @"<strong>Success!</strong> Membership Enrollment Email Sent"; } else { user = UserManager.FindByEmail(user.Email); } string code = UserManager.GeneratePasswordResetToken<ApplicationUser, string>(user.Id); callbackUrl = Url.Action("ResetPassword", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme); //if (HttpContext.Request.IsLocal) //{ // MandrillMailer mandrillMailer = new MandrillMailer(); // mandrillMailer.SendNewMembershipAccountCreation(user.Email, callbackUrl); //} MandrillMailer mandrillMailer = new MandrillMailer(); mandrillMailer.SendNewMembershipAccountCreation(user.Email, callbackUrl); TempData["SuccessAlertCustom"] = @"<strong>Success!</strong> Membership Enrollment Email Sent"; if (HttpContext.Request.IsLocal) { return RedirectToAction("ConfirmLink", new { link = callbackUrl }); } else { return RedirectToAction("Index", "Person"); } }