Exemple #1
0
        public void Update(Cliente cliente)
        {
            var idPessoa = cliente.Id;

            if (idPessoa > 0)
            {
                new PessoaRepositorio(this._context, this._transaction).Update(cliente.ToPessoa());
            }
            else
            {
                new PessoaRepositorio(this._context, this._transaction).Create(cliente.ToPessoa());
                var pessoaInsert = new PessoaRepositorio(this._context, this._transaction).GetByCpfCnpj(cliente.cpfCnpj);

                if (pessoaInsert != null)
                {
                    idPessoa = pessoaInsert.Id;
                }
            }

            var query   = "UPDATE public.Cliente SET ativo = @ativo, tipoCliente = @tipoCliente, nascimento = @nascimento, fk_IdPessoa = @fk_IdPessoa WHERE idCliente = @id";
            var command = CreateCommand(query);

            command.Parameters.AddWithValue("@tipoCliente", cliente.tipoCliente);
            command.Parameters.AddWithValue("@ativo", cliente.ativo);
            command.Parameters.AddWithValue("@nascimento", cliente.nascimento);
            command.Parameters.AddWithValue("@fk_IdPessoa", idPessoa);
            command.Parameters.AddWithValue("@id", cliente.Id);

            command.ExecuteNonQuery();
        }
Exemple #2
0
        public void Update(Fornecedor fornecedor)
        {
            var idPessoa = fornecedor.Id;

            if (idPessoa > 0)
            {
                new PessoaRepositorio(this._context, this._transaction).Update(fornecedor.ToPessoa());
            }
            else
            {
                new PessoaRepositorio(this._context, this._transaction).Create(fornecedor.ToPessoa());
                var pessoaInsert = new PessoaRepositorio(this._context, this._transaction).GetByCpfCnpj(fornecedor.cpfCnpj);

                if (pessoaInsert != null)
                {
                    idPessoa = pessoaInsert.Id;
                }
            }

            var query   = "UPDATE public.Fornecedor SET ativo = @ativo, tipoFornecedor = @tipoFornecedor, fk_IdPessoa = @fk_IdPessoa WHERE idFornecedor = @id";
            var command = CreateCommand(query);

            command.Parameters.AddWithValue("@ativo", fornecedor.ativo);
            command.Parameters.AddWithValue("@tipoFornecedor", fornecedor.tipoFornecedor);
            command.Parameters.AddWithValue("@fk_IdPessoa", idPessoa);
            command.Parameters.AddWithValue("@id", fornecedor.Id);

            command.ExecuteNonQuery();
        }
Exemple #3
0
        public void Create(Cliente cliente)
        {
            bool inseriuNovo = false;
            var  idPessoa    = cliente.Id;

            if (idPessoa > 0)
            {
                new PessoaRepositorio(this._context, this._transaction).Update(cliente.ToPessoa());
            }
            else
            {
                var pessoaInsert = new PessoaRepositorio(this._context, this._transaction).GetByCpfCnpj(cliente.ToPessoa().cpfCnpj);
                if (pessoaInsert == null)
                {
                    inseriuNovo = true;
                    new PessoaRepositorio(this._context, this._transaction).Create(cliente.ToPessoa());
                    pessoaInsert = new PessoaRepositorio(this._context, this._transaction).GetByCpfCnpj(cliente.cpfCnpj);
                }

                if (pessoaInsert != null)
                {
                    idPessoa   = pessoaInsert.Id;
                    cliente.Id = idPessoa;
                    if (!inseriuNovo)
                    {
                        new PessoaRepositorio(this._context, this._transaction).Update(cliente.ToPessoa());
                    }
                }
            }

            var query = "INSERT INTO public.Cliente(tipoCliente, ativo, nascimento, fk_IdPessoa) " +
                        " VALUES (@tipoCliente, @ativo, @nascimento, @fk_IdPessoa) ";
            var command = CreateCommand(query);

            command.Parameters.AddWithValue("@tipoCliente", cliente.tipoCliente);
            command.Parameters.AddWithValue("@ativo", cliente.ativo);
            command.Parameters.AddWithValue("@nascimento", cliente.nascimento);
            command.Parameters.AddWithValue("@fk_IdPessoa", idPessoa);

            command.ExecuteNonQuery();


            query   = "select currval('cliente_idcliente_seq') as newId";
            command = CreateCommand(query);

            using (var reader = command.ExecuteReader())
            {
                reader.Read();
                if (reader.HasRows)
                {
                    cliente.idCliente = Convert.ToInt32(reader["newId"]);
                }
            }
        }
Exemple #4
0
        public void Create(Fornecedor fornecedor)
        {
            bool inseriuNovo = false;
            var  idPessoa    = fornecedor.Id;

            if (idPessoa > 0)
            {
                new PessoaRepositorio(this._context, this._transaction).Update(fornecedor.ToPessoa());
            }
            else
            {
                var pessoaInsert = new PessoaRepositorio(this._context, this._transaction).GetByCpfCnpj(fornecedor.ToPessoa().cpfCnpj);
                if (pessoaInsert == null)
                {
                    inseriuNovo = true;
                    new PessoaRepositorio(this._context, this._transaction).Create(fornecedor.ToPessoa());
                    pessoaInsert = new PessoaRepositorio(this._context, this._transaction).GetByCpfCnpj(fornecedor.cpfCnpj);
                }

                if (pessoaInsert != null)
                {
                    idPessoa      = pessoaInsert.Id;
                    fornecedor.Id = idPessoa;
                    if (!inseriuNovo)
                    {
                        new PessoaRepositorio(this._context, this._transaction).Update(fornecedor.ToPessoa());
                    }
                }
            }

            var query = "INSERT INTO public.Fornecedor(ativo, tipoFornecedor, fk_IdPessoa) " +
                        " VALUES (@ativo, @tipoFornecedor, @fk_IdPessoa) ";
            var command = CreateCommand(query);

            command.Parameters.AddWithValue("@ativo", fornecedor.ativo);
            command.Parameters.AddWithValue("@tipoFornecedor", fornecedor.tipoFornecedor);
            command.Parameters.AddWithValue("@fk_IdPessoa", idPessoa);

            command.ExecuteNonQuery();

            query   = "select currval('fornecedor_idfornecedor_seq') as newId";
            command = CreateCommand(query);

            using (var reader = command.ExecuteReader())
            {
                reader.Read();
                if (reader.HasRows)
                {
                    fornecedor.idFornecedor = Convert.ToInt32(reader["newId"]);
                }
            }
        }