Exemplo n.º 1
0
        public ActionResult Cadastrar(Empresa Empresa)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    //Empresa.UsuarioInclusao = CustomAuthorizationProvider.UsuarioAutenticado.Login;
                    Empresa.UsuarioInclusao = "Antonio";
                    EmpresaBusiness.Inserir(Empresa);

                    Extensions.GravaCookie("MensagemSucesso", "A empresa '" + Empresa.NomeFantasia + "' foi cadastrada com sucesso.", 10);


                    return(Json(new { resultado = new RetornoJSON()
                                      {
                                          URL = Url.Action("Index", "Empresa")
                                      } }));
                }
                catch (Exception ex) {
                    if (ex.GetBaseException() == null)
                    {
                        return(Json(new { resultado = new RetornoJSON()
                                          {
                                              Erro = ex.Message
                                          } }));
                    }
                    else
                    {
                        return(Json(new { resultado = new RetornoJSON()
                                          {
                                              Erro = ex.GetBaseException().Message
                                          } }));
                    }
                }
            }
            else
            {
                return(Json(new { resultado = TratarRetornoValidacaoToJSON() }));
            }
        }
Exemplo n.º 2
0
        public ActionResult Cadastrar(Empresa Empresa)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    EmpresaBusiness.Inserir(Empresa);

                    TempData["MensagemSucesso"] = "A empresa '" + Empresa.NomeFantasia + "' foi cadastrada com sucesso.";

                    return(Json(new { resultado = new RetornoJSON()
                                      {
                                          URL = Url.Action("Index", "Empresa")
                                      } }));
                }
                catch (Exception ex) {
                    if (ex.GetBaseException() == null)
                    {
                        return(Json(new { resultado = new RetornoJSON()
                                          {
                                              Erro = ex.Message
                                          } }));
                    }
                    else
                    {
                        return(Json(new { resultado = new RetornoJSON()
                                          {
                                              Erro = ex.GetBaseException().Message
                                          } }));
                    }
                }
            }
            else
            {
                return(Json(new { resultado = TratarRetornoValidacaoToJSON() }));
            }
        }