public ActionResult Create(AdotanteViewModel vm) { if (!ModelState.IsValid) { vm.Adotantes = _context.Adotantes.ToList(); vm.Especies = _context.Especies.ToList(); vm.Portes = _context.Portes.ToList(); vm.Heading = "Adicionar Adotante"; vm.Botao = "Adicionar"; return(View("AdotanteForm", vm)); } var adotante = new Adotante { Nome = vm.Nome, Endereco = vm.Endereco, Telefone = vm.Telefone, EspecieId = vm.Especie, PorteId = vm.Porte }; _context.Adotantes.Add(adotante); _context.SaveChanges(); return(RedirectToAction("Create", "Adotante")); }
public ActionResult Edit(int id) { var adotante = _context.Adotantes.SingleOrDefault(x => x.Id == id); if (adotante == null) { return(RedirectToAction("Create", "Adotante")); } var vm = new AdotanteViewModel { Id = id, Nome = adotante.Nome, Endereco = adotante.Endereco, Telefone = adotante.Telefone, Adotantes = _context.Adotantes.ToList(), Especie = adotante.EspecieId, Porte = adotante.PorteId, Especies = _context.Especies.ToList(), Portes = _context.Portes.ToList(), Heading = "Editar Adotante", Botao = "Editar" }; return(View("AdotanteForm", vm)); }
public IActionResult Criar(AdotanteViewModel adotante) { if (ModelState.IsValid) { _adotanteService.Adicionar(adotante); return(RedirectToAction(nameof(Index))); } return(View(adotante)); }
public ActionResult Create() { var vm = new AdotanteViewModel { Adotantes = _context.Adotantes.ToList(), Especies = _context.Especies.ToList(), Portes = _context.Portes.ToList(), Heading = "Adicionar Adotante", Botao = "Adicionar" }; return(View("AdotanteForm", vm)); }
public ActionResult Update(AdotanteViewModel vm) { var adotante = _context.Adotantes.SingleOrDefault(x => x.Id == vm.Id); if (adotante == null) { return(RedirectToAction("Create", "Adotante")); } adotante.Nome = vm.Nome; adotante.Endereco = vm.Endereco; adotante.Telefone = vm.Telefone; adotante.PorteId = vm.Porte; adotante.EspecieId = vm.Especie; _context.SaveChanges(); return(RedirectToAction("Create", "Adotante")); }
public IActionResult Editar(int id, AdotanteViewModel adotante) { if (id != adotante.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _adotanteService.Atualizar(adotante); } catch (DbUpdateConcurrencyException) { throw; } return(RedirectToAction(nameof(Index))); } return(View(adotante)); }
public AdotanteViewModel Atualizar(AdotanteViewModel adotanteViewModel) { var adotante = _adotanteRepository.Alterar(_mapper.Map <Adotante>(adotanteViewModel)); return(_mapper.Map <AdotanteViewModel>(adotante)); }
public void Adicionar(AdotanteViewModel adotanteViewModel) { Adotante adotante = _mapper.Map <Adotante>(adotanteViewModel); _adotanteRepository.Inserir(adotante); }