public IActionResult Inserir(OngViewModel ong) { if (!ModelState.IsValid) { return(Retorno(ModelState)); } _ongService.Adicionar(ong); return(Retorno(ong)); }
public IActionResult Criar(OngViewModel ong) { if (ModelState.IsValid) { _ongService.Adicionar(ong); return(RedirectToAction(nameof(Index))); } return(View(ong)); }
public async Task <ActionResult> Registrar(RegistrarUsuarioViewModel registrarUsuario) { if (!ModelState.IsValid) { return(Retorno(ModelState)); } var user = new IdentityUser { UserName = registrarUsuario.Email, Email = registrarUsuario.Email, EmailConfirmed = true }; var resultUser = await _userManager.CreateAsync(user, registrarUsuario.Password); try { if (resultUser.Succeeded) { await _signInManager.SignInAsync(user, false); var ong = registrarUsuario.Ong; ong.IdUsuario = user.Id; ong.Usuario = user; var resultOng = _ongService.Adicionar(ong); if (!resultOng) { await _userManager.DeleteAsync(user); } else { return(Retorno(await GerarToken(registrarUsuario.Email))); } } foreach (var erro in resultUser.Errors) { NotificarErro(erro.Description); } } catch (Exception e) { NotificarErro("Comportamento Inesperado"); } return(Retorno()); }
public OngEnderecoViewModel Adicionar(OngEnderecoViewModel ongEnderecoViewModel) { var ong = Mapper.Map <Ong>(ongEnderecoViewModel); var endereco = Mapper.Map <Endereco>(ongEnderecoViewModel); ong.Enderecos.Add(endereco); var ongReturn = _ongService.Adicionar(ong); if (ongReturn.ValidationResult.IsValid) { ong.Ativo = true; Commit(); } return(Mapper.Map <OngEnderecoViewModel>(ongReturn)); }