public async Task <IActionResult> Salvar(AlteracaoViewModel viewModel)
        {
            if (!ModelState.IsValid)
            {
                return(View("Alteracao", viewModel));
            }
            var res = await _usuarioService.Salvar(viewModel);

            if (res)
            {
                return(RedirectToAction("IndexUsuario", "Home"));
            }
            return(View("Alteracao"));
        }
Example #2
0
        public async Task <bool> Salvar(AlteracaoViewModel viewModel)
        {
            var conta = new Conta(viewModel.Nome, Enum.Parse <ESexoConta>(viewModel.Sexo), viewModel.DataNascimento, viewModel.CPF, viewModel.PlanoId);

            conta.Id = viewModel.Id;
            var usuario = await _userManager.FindByIdAsync(viewModel.IdUsuario);

            _contaRepository.Atualizar(viewModel.Id, conta);
            var resultadoCommit = _uow.Commit();

            if (resultadoCommit == false)
            {
                return(resultadoCommit);
            }

            if (!String.IsNullOrEmpty(viewModel.Senha))
            {
                var resultadoIdentity = await _userManager.ChangePasswordAsync(usuario, viewModel.SenhaAntiga, viewModel.Senha);

                return(resultadoIdentity.Succeeded);
            }
            return(true);
        }