Exemple #1
0
        private bool ValidarOng(Ong ong, OngViewModel ongViewModel, bool atualizar = false)
        {
            bool temErro = false;

            if (atualizar && ong == null)
            {
                Notificar("Ong não encontrada.");
                return(true);
            }

            if (_ongRepository.Obter(o => o.Cnpj == ongViewModel.Cnpj && o.Id != ongViewModel.Id).Any())
            {
                Notificar("Já existe uma ONG com este CNPJ.");
                temErro = true;
            }

            if (_ongRepository.Obter(o => o.Nome == ongViewModel.Nome && o.Id != ongViewModel.Id).Any())
            {
                Notificar("Já existe uma ONG com este Nome.");
                temErro = true;
            }

            if (!ExecutarValidacao(new OngValidation(), ong))
            {
                temErro = true;
            }

            return(temErro);
        }
        public OngViewModel Atualizar(OngViewModel ongViewModel)
        {
            var ong = Mapper.Map <Ong>(ongViewModel);

            _ongService.Atualizar(ong);
            ong.Ativo = true;
            Commit();
            return(ongViewModel);
        }
Exemple #3
0
 public IActionResult Criar(OngViewModel ong)
 {
     if (ModelState.IsValid)
     {
         _ongService.Adicionar(ong);
         return(RedirectToAction(nameof(Index)));
     }
     return(View(ong));
 }
Exemple #4
0
 public ActionResult Edit(OngViewModel ongViewModel)
 {
     if (ModelState.IsValid)
     {
         _ongAppService.Atualizar(ongViewModel);
         return(RedirectToAction("Index"));
     }
     return(View(ongViewModel));
 }
Exemple #5
0
 public IActionResult Inserir(OngViewModel ong)
 {
     if (!ModelState.IsValid)
     {
         return(Retorno(ModelState));
     }
     _ongService.Adicionar(ong);
     return(Retorno(ong));
 }
Exemple #6
0
        public bool Atualizar(OngViewModel ongViewModel, int id)
        {
            Ong  ong     = _mapper.Map <Ong>(ongViewModel);
            bool temErro = ValidarOng(ong, ongViewModel, true);

            if (!temErro)
            {
                _ongRepository.Alterar(ong);
            }
            return(!temErro);
        }
Exemple #7
0
        public bool Adicionar(OngViewModel ongViewModel)
        {
            Ong  ong     = _mapper.Map <Ong>(ongViewModel);
            bool temErro = ValidarOng(ong, ongViewModel);

            if (!temErro)
            {
                _ongRepository.Inserir(ong);
            }
            return(!temErro);
        }
Exemple #8
0
        public IActionResult Atualizar(OngViewModel ongViewModel, int id)
        {
            if (id != ongViewModel.Id)
            {
                NotificarErro("Os ids informados não são idênticos!");
                Retorno();
            }
            if (!ModelState.IsValid)
            {
                return(Retorno(ongViewModel));
            }


            return(Retorno(_ongService.Atualizar(ongViewModel, id)));
        }
Exemple #9
0
        public IActionResult Editar(int id, OngViewModel ong)
        {
            if (id != ong.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _ongService.Atualizar(ong, id);
                }
                catch (DbUpdateConcurrencyException)
                {
                    throw;
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(ong));
        }