Ejemplo n.º 1
0
        public JsonResult Excluir(int id_estabelecimento)
        {
            retornoJson ret = new retornoJson();
            int         retorno;

            using (Contexto c = new Contexto(cnx))
            {
                retorno = c.ExecuteCommand("delete from [dbo].[Estabelecimento] where id_estabelecimento =" + id_estabelecimento);
            }

            if (retorno == 1)
            {
                ret.Mensagem = "Estabelecimento excluido";
                ret.sucesso  = true;
            }
            else
            {
                ret.Mensagem = "Ocorreu uma falha";
                ret.sucesso  = false;
            }

            return(Json(ret, JsonRequestBehavior.AllowGet));
        }
Ejemplo n.º 2
0
        public JsonResult Editar(clsEstabelecimento estabelecimento)
        {
            retornoJson ret = new retornoJson();
            int         retorno;

            //Validações
            if (string.IsNullOrWhiteSpace(estabelecimento.razao_social))
            {
                ret.Mensagem += "Razão Social é um campo obrigatorio <br/>";
            }

            if (string.IsNullOrWhiteSpace(estabelecimento.cnpj))
            {
                ret.Mensagem += "CNPJ é um campo obrigatorio <br/>";
            }

            if (estabelecimento.id_categoria == 0)
            {
                ret.Mensagem += "Selecione a categoria <br/>";
            }

            if (estabelecimento.id_categoria == 1)
            {
                if (string.IsNullOrWhiteSpace(estabelecimento.telefone))
                {
                    ret.Mensagem += "Para a categoria SUPERMERCADO o telefone passa a ser obrigatorio. <br/>";
                }
            }

            if (!string.IsNullOrWhiteSpace(estabelecimento.email))
            {
                if (Funcoes.IsEmail(estabelecimento.email) != true)
                {
                    ret.Mensagem += "Formato de e-mail invalido. Use um e-mail valido. ex: [email protected] <br/>";
                }
            }

            if (ret.Mensagem != null && ret.Mensagem != "")
            {
                return(Json(ret, JsonRequestBehavior.AllowGet));
            }

            using (Contexto c = new Contexto(cnx))
            {
                retorno = c.ExecuteCommand("[dbo].[estabelecimento_editar] {0},{1},{2},{3},{4},{5},{6},{7},{8},{9},{10},{11},{12}",
                                           estabelecimento.id_estabelecimento, /*obrigatorio*/
                                           estabelecimento.razao_social,       /*obrigatorio*/
                                           string.IsNullOrWhiteSpace(estabelecimento.nome_fantasia) ? "" : estabelecimento.nome_fantasia,
                                           estabelecimento.cnpj,               /*obrigatorio*/
                                           string.IsNullOrWhiteSpace(estabelecimento.email) ? "" : estabelecimento.email,
                                           string.IsNullOrWhiteSpace(estabelecimento.endereco) ? "" : estabelecimento.endereco,
                                           estabelecimento.id_cidade,
                                           estabelecimento.id_estado,
                                           string.IsNullOrWhiteSpace(estabelecimento.telefone) ? "" : estabelecimento.telefone,
                                           estabelecimento.id_categoria, /*obrigatorio*/
                                           estabelecimento.status,
                                           string.IsNullOrWhiteSpace(estabelecimento.agencia) ? "" : estabelecimento.agencia,
                                           string.IsNullOrWhiteSpace(estabelecimento.conta) ? "" : estabelecimento.conta
                                           );

                c.Connection.Close();
                c.Connection.Dispose();
            }

            if (retorno == -1)
            {
                ret.Mensagem = "Este CNPJ ou este E-mail já esta cadastrado";
                ret.sucesso  = false;
            }
            else if (retorno > 0)
            {
                ret.Mensagem = "Cadastrado com sucesso";
                ret.sucesso  = true;
            }
            else
            {
                ret.Mensagem = "Não foi possivel realizar o cadastro";
                ret.sucesso  = false;
            }

            return(Json(ret, JsonRequestBehavior.AllowGet));
        }