Exemplo n.º 1
0
 public ActionResult Edit(AgenteAmbientalViewModel agenteAmbientalViewModel)
 {
     if (ModelState.IsValid)
     {
         if (!_agenteAmbientalAppService.Atualizar(agenteAmbientalViewModel))
         {
             System.Web.HttpContext.Current.Response.Write("<SCRIPT> alert('Atenção, há um Agente Ambiental com os mesmos dados já cadastrado')</SCRIPT>");
         }
         else
         {
             return(RedirectToAction("Index"));
         }
     }
     return(View(agenteAmbientalViewModel));
 }
Exemplo n.º 2
0
 public ActionResult Create(AgenteAmbientalViewModel agenteAmbientalViewModel)
 {
     if (ModelState.IsValid)
     {
         if (!_agenteAmbientalAppService.Adicionar(agenteAmbientalViewModel))
         {
             TempData["Mensagem"] = "Atenção, há um Agente Ambiental com os mesmos dados";
             //System.Web.HttpContext.Current.Response.Write("<SCRIPT> alert('Atenção, há um tipoCurso com os mesmos dados')</SCRIPT>");
         }
         else
         {
             return(RedirectToAction("Index"));
         }
     }
     return(View(agenteAmbientalViewModel));
 }
        public bool Adicionar(AgenteAmbientalViewModel agenteAmbientalViewModel)
        {
            var agenteAmbiental = Mapper.Map <AgenteAmbientalViewModel, AgenteAmbiental>(agenteAmbientalViewModel);

            var duplicado = _agenteAmbientalService.Find(x => (x.Nome == agenteAmbiental.Nome) &&
                                                         (x.Delete == false)).Any();

            if (duplicado)
            {
                return(false);
            }
            else
            {
                BeginTransaction();
                _agenteAmbientalService.Adicionar(agenteAmbiental);
                Commit();
                return(true);
            }
        }