public async Task <IActionResult> Index(UserRegisterModel model)
        {
            // Ignore properties
            ModelState.Remove(nameof(model.UserName));
            ModelState.Remove(nameof(model.Password));
            ModelState.Remove(nameof(model.PasswordConfirm));

            ApplicationUser currentUser = await userManager.GetUserAsync(User);

            if (ModelState.IsValid)
            {
                // Update user
                model.UserName = currentUser.UserName;
                model.ApplyToApplicationUser(currentUser);
                await dbContext.SaveChangesAsync();
            }

            return(View(new UserRegisterModel(currentUser)));
        }
        public async Task <IActionResult> Register(UserRegisterModel register)
        {
            if (signInManager.IsSignedIn(User))
            {
                return(RedirectToAction("Index"));
            }

            if (!ModelState.IsValid)
            {
                return(View(register));
            }

            var user = new ApplicationUser();

            register.ApplyToApplicationUser(user);

            IdentityResult result = await userManager.CreateAsync(user, register.Password);

            if (!result.Succeeded)
            {
                foreach (IdentityError error in result.Errors)
                {
                    ModelState.AddModelError(
                        error.Description.IndexOf("password", StringComparison.CurrentCultureIgnoreCase) != -1
                                                        ? nameof(register.Password)
                                                        : nameof(register.UserName), error.Description);
                }

                return(View(register));
            }

            await userManager.AddToRoleAsync(user, UserRole.RegularUser);

            await signInManager.SignOutAsync();

            await signInManager.SignInAsync(user, false);

            return(RedirectToAction("Index"));
        }