Ejemplo n.º 1
0
        public IActionResult Edit(CitizenViewModel citizenViewModel)
        {
            if (!ModelState.IsValid)
            {
                return(View(citizenViewModel));
            }

            _citizenAppService.Update(citizenViewModel);

            return(RedirectToAction("Index"));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> OnPostChangeEmailAsync()
        {
            var user = await _userManager.GetUserAsync(User);

            if (user == null)
            {
                return(NotFound($"Não foi possível carregar o usuário com o ID '{_userManager.GetUserId(User)}'."));
            }

            if (!ModelState.IsValid)
            {
                await LoadAsync(user);

                return(Page());
            }

            var citizen = new CitizenViewModel
            {
                Id       = Guid.Parse(user.Id),
                Name     = Input.Name,
                NickName = Input.NickName,
                Document = Input.Document,
                Email    = Input.NewEmail,
                Gender   = Input.Gender
            };

            _citizenAppService.Update(citizen);

            if (!IsValidOperation())
            {
                return(ErrorUpdate());
            }

            var email = await _userManager.GetEmailAsync(user);

            if (Input.NewEmail != email)
            {
                //var userId = await _userManager.GetUserIdAsync(user);
                //var code = await _userManager.GenerateChangeEmailTokenAsync(user, Input.NewEmail);

                //var callbackUrl = Url.Page(
                //    "/Account/ConfirmEmailChange",
                //    pageHandler: null,
                //    values: new { userId = userId, email = Input.NewEmail, code = code },
                //    protocol: Request.Scheme);
                //await _emailSender.SendEmailAsync(
                //    Input.NewEmail,
                //    "Confirm your email",
                //    $"Please confirm your account by <a href='{HtmlEncoder.Default.Encode(callbackUrl)}'>clicking here</a>.");

                user.Email    = Input.NewEmail;
                user.UserName = Input.NewEmail;
                var result = await _userManager.UpdateAsync(user);

                if (!result.Succeeded)
                {
                    return(ErrorUpdate());
                }

                // StatusMessage = "Confirmation link to change email sent. Please check your email.";
                StatusMessage = "Dados Atualizados com sucesso!";
                return(RedirectToPage());
            }

            StatusMessage = "Dados Atualizados com sucesso!";
            return(RedirectToPage());
        }