public ActionResult Register([Bind(Include = "UserName, UserPnom, UserMail, UserPhone, UserSexe, Password, ConfirmPassword")] RegisterViewMode model) { if (ModelState.IsValid) { using (var db = new DbCaimanContext()) { User user = new User(); user.UserName = model.UserName; user.UserPnom = model.UserPnom; user.UserMail = model.UserMail; user.UserSexe = model.UserSexe; user.UserPhone = model.UserPhone; user.Password = model.Password; user.ConfirmPassword = model.ConfirmPassword; db.Users.Add(user); db.SaveChanges(); } ViewBag.Message = "Utilisateur Enregistré"; ModelState.Clear(); //Nettoyage des champs du formulaire return(View("Register")); } else { return(View("Register", model)); } }
public async Task <ActionResult> Register(RegisterViewMode model) { if (ModelState.IsValid) { var user = new IdentityUser { UserName = model.UserName }; var userManager = new UserManager <IdentityUser, string>(new UserStore <IdentityUser>(new BlogIdentityDbContext())); var result = await userManager.CreateAsync(user, model.Password); if (result.Succeeded) { return(RedirectToAction("Index", "Home")); } } return(View(model)); }