Exemplo n.º 1
0
 public void Save(npj entity)
 {
     DataModel.Entry(entity).State = entity.id_npj == 0 ?
                                     EntityState.Added :
                                     EntityState.Modified;
     DataModel.SaveChanges();
 }
Exemplo n.º 2
0
        public bool validate(npj entity)
        {
            bool retorno = false;

            if (string.IsNullOrEmpty(entity.nome_npj))
            {
                ModelState.AddModelError("nome_npj", "Campo obrigatório");
                retorno = true;
            }
            if (string.IsNullOrEmpty(entity.cnpj_npj))
            {
                ModelState.AddModelError("cnpj_npj", "Campo obrigatório");
                retorno = true;
            }
            if (!ValidaCNPJ(entity.cnpj_npj))
            {
                ModelState.AddModelError("cnpj_npj", "CNPJ inválido");
                retorno = true;
            }
            if (string.IsNullOrEmpty(entity.endereco_npj))
            {
                ModelState.AddModelError("endereco_npj", "Campo obrigatório");
                retorno = true;
            }
            if (string.IsNullOrEmpty(entity.telefone_npj))
            {
                ModelState.AddModelError("telefone_npj", "Campo obrigatório");
                retorno = true;
            }

            return(retorno);
        }
Exemplo n.º 3
0
 public ActionResult List(npj entity, String message, String messageError)
 {
     ViewData["message"]      = message;
     ViewData["messageError"] = messageError;
     if (string.IsNullOrEmpty(entity.cnpj_npj) && (string.IsNullOrEmpty(entity.nome_npj)))
     {
         return(View(NPJRepository.GetAll()));
     }
     else
     {
         return(View(NPJRepository.GetAllByCriteria(entity.nome_npj, entity.cnpj_npj)));
     }
 }
Exemplo n.º 4
0
        public ActionResult Edit(int id, npj npj)
        {
            LoadFormFaculdade();

            try
            {
                if (validate(npj))
                {
                    return(View(npj));
                }

                NPJRepository.Edit(npj);
                return(RedirectToAction("List", new { message = "Dados editados com sucesso!" }));
            }
            catch
            {
                return(View());
            }
        }
Exemplo n.º 5
0
        public ActionResult Delete(int id, npj npj)
        {
            try
            {
                npj = NPJRepository.GetOne(id);

                if (npj.juri.Count > 0)
                {
                    return(RedirectToAction("List", new { messageError = "Esse NPJ possui registros vinculados a seu cadastro. Não é possível excluí-lo." }));
                }

                NPJRepository.Delete(npj);

                return(RedirectToAction("List", new { message = "Dados excluídos com sucesso!" }));
            }
            catch
            {
                return(View());
            }
        }
Exemplo n.º 6
0
 public void Delete(npj entity)
 {
     DataModel.npj.Remove(entity);
     DataModel.SaveChanges();
 }
Exemplo n.º 7
0
 public void Edit(npj entity)
 {
     Save(entity);
 }
Exemplo n.º 8
0
 public void Create(npj entity)
 {
     Save(entity);
 }