Ejemplo n.º 1
0
        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)
                {
                    #region Custom User Details
                    UserDetail newUserDetails = new UserDetail()
                    {
                        UserID = user.Id, FirstName = model.FirstName, LastName = model.LastName
                    };

                    VintageMediaStoreEntities db = new VintageMediaStoreEntities();
                    db.UserDetails.Add(newUserDetails);
                    db.SaveChanges();
                    #endregion

                    UserManager.AddToRole(user.Id, "Customer");
                    var trySignIn = await SignInManager.PasswordSignInAsync(user.UserName, model.Password, false, false);

                    return(RedirectToAction("Index", "Home"));
                }
                AddErrors(result);
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }