public ActionResult Register(int t) { Session["type"] = t; if (t == 1) { var userID = User.Identity.GetUserId(); var obj = new AddTitleAndQuestions(); Session["CId"] = int.Parse(obj.getCompanyIdforAcc(userID)); } return(View()); }
public async Task <JsonResult> RegisterAllAsync(List <RegisterMutlipleUsers> model) { var successful = new List <RegisterMutlipleUsers>(); var failed = new List <RegisterMutlipleUsers>(); var userID = User.Identity.GetUserId(); var obj = new AddTitleAndQuestions(); Session["CId"] = int.Parse(obj.getCompanyIdforAcc(userID)); foreach (var eachuser in model) { using (var context = new ApplicationDbContext()) { var user = new ApplicationUser { UserName = eachuser.Email, Email = eachuser.Email }; var result = await UserManager.CreateAsync(user, eachuser.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"); var status = obj.AssignCompanyForUsers(user.Id, int.Parse(Session["CId"].ToString())); 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>"); var a = new RegisterMutlipleUsers(); a.Email = eachuser.Email; successful.Add(a); } else { var a = new RegisterMutlipleUsers(); a.Email = eachuser.Email; failed.Add(a); } } } return(Json(new { SuccessfullyRegistered = successful, FailedToRegister = failed }, JsonRequestBehavior.AllowGet)); }