예제 #1
0
        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"));
        }
예제 #2
0
        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));
        }
예제 #3
0
 public IActionResult Criar(AdotanteViewModel adotante)
 {
     if (ModelState.IsValid)
     {
         _adotanteService.Adicionar(adotante);
         return(RedirectToAction(nameof(Index)));
     }
     return(View(adotante));
 }
예제 #4
0
        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));
        }
예제 #5
0
        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"));
        }
예제 #6
0
        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));
        }
예제 #7
0
        public AdotanteViewModel Atualizar(AdotanteViewModel adotanteViewModel)
        {
            var adotante = _adotanteRepository.Alterar(_mapper.Map <Adotante>(adotanteViewModel));

            return(_mapper.Map <AdotanteViewModel>(adotante));
        }
예제 #8
0
        public void Adicionar(AdotanteViewModel adotanteViewModel)
        {
            Adotante adotante = _mapper.Map <Adotante>(adotanteViewModel);

            _adotanteRepository.Inserir(adotante);
        }