private void CheckedCliente(ClienteDomain ClienteObj = null, IEnumerable <ClienteDomain> ListClientObj = null)
        {
            var listaCloente = new List <ClienteDomain>();

            if (ListClientObj != null)
            {
                listaCloente = ListClientObj.ToList();
            }

            if (ClienteObj != null)
            {
                listaCloente.Add(ClienteObj);
            }

            foreach (var obj in listaCloente)
            {
                DomainException.When(string.IsNullOrEmpty(obj.ClienteNome), ErrorMessages.CLIENTENOME);
                DomainException.When(string.IsNullOrEmpty(obj.ClienteCep), ErrorMessages.CEP);
                DomainException.When(string.IsNullOrEmpty(obj.ClienteRua), ErrorMessages.LOGRADOURO);
                DomainException.When(string.IsNullOrEmpty(obj.ClienteNumero), ErrorMessages.NUMERO);
                DomainException.When(string.IsNullOrEmpty(obj.ClienteBairro), ErrorMessages.BAIRRO);
                DomainException.When(string.IsNullOrEmpty(obj.ClienteCidade), ErrorMessages.CIDADE);
                DomainException.When(string.IsNullOrEmpty(obj.ClienteEstado), ErrorMessages.ESTADO);
            }
        }
Example #2
0
        public int Insert(ClienteDomain model)
        {
            int retorno = 0;

            using (SqlConnection conn = new SqlConnection(SqlConnectionString))
            {
                try
                {
                    conn.Open();

                    using (SqlCommand comm = conn.CreateCommand())
                    {
                        comm.CommandType = CommandType.Text;
                        comm.CommandText = " INSERT INTO CLIENTE (NOME,IDADE,EMAIL,DATANASCIMENTO) VALUES(@NOME,@IDADE,@EMAIL,@DATANASCIMENTO) SELECT @@IDENTITY ";

                        comm.Parameters.Add(new SqlParameter("@NOME", model.Nome));
                        comm.Parameters.Add(new SqlParameter("@IDADE", model.Idade));
                        comm.Parameters.Add(new SqlParameter("@EMAIL", model.Email));
                        comm.Parameters.Add(new SqlParameter("@DATANASCIMENTO", model.DataNascimento));

                        retorno = comm.ExecuteNonQuery();
                    }

                    return(retorno);
                }
                catch (Exception ex)
                {
                    throw new Exception($"{ex.Message} - {ex.StackTrace}");
                }
                finally
                {
                    conn.Close();
                }
            }
        }
Example #3
0
        public IEnumerable <ClienteDomain> GetAll(ClienteArgs args)
        {
            List <ClienteDomain> retorno = new List <ClienteDomain>();

            using (SqlConnection conn = new SqlConnection(SqlConnectionString))
            {
                try
                {
                    conn.Open();

                    using (SqlCommand comm = conn.CreateCommand())
                    {
                        comm.CommandType = CommandType.Text;
                        comm.CommandText = " SELECT * FROM CLIENTE WHERE ID > 0 ";

                        if (args.Id > 0)
                        {
                            comm.CommandText += " AND ID = @ID ";
                            comm.Parameters.Add(new SqlParameter("@ID", args.Id));
                        }

                        if (!string.IsNullOrEmpty(args.Nome))
                        {
                            comm.CommandText += " AND NOME = @NOME ";
                            comm.Parameters.Add(new SqlParameter("@NOME", args.Nome));
                        }

                        using (SqlDataReader reader = comm.ExecuteReader())
                        {
                            if (reader.HasRows)
                            {
                                while (reader.Read())
                                {
                                    var cliente = new ClienteDomain();

                                    cliente.Id             = int.Parse(reader["ID"].ToString());
                                    cliente.Nome           = reader["NOME"].ToString();
                                    cliente.Idade          = short.Parse(reader["IDADE"].ToString());
                                    cliente.Email          = reader["EMAIL"].ToString();
                                    cliente.DataNascimento = DateTime.Parse(reader["DATANASCIMENTO"].ToString());

                                    retorno.Add(cliente);
                                }
                            }
                        }
                    }

                    return(retorno);
                }
                catch (Exception ex)
                {
                    throw new Exception($"{ex.Message} - {ex.StackTrace}");
                }
                finally
                {
                    conn.Close();
                }
            }
        }
Example #4
0
 public ProdutoDomain(Guid id, string nome, Guid?fornecedorId, ClienteDomain fornecedor, int quantidade, decimal preco)
 {
     Id           = id;
     Nome         = nome;
     FornecedorId = fornecedorId;
     Fornecedor   = fornecedor;
     Quantidade   = quantidade;
     Preco        = preco;
 }
Example #5
0
 public VendaDomain(Guid id, Guid?usuarioId, UsuarioDomain usuario, Guid?clienteId,
                    ClienteDomain cliente, Guid?formaDePagamentoId, FormaDePagamentoDomain formaDePagamento, decimal valorTotal)
 {
     Id                 = id;
     UsuarioId          = usuarioId;
     Usuario            = usuario;
     ClienteId          = clienteId;
     Cliente            = cliente;
     FormaDePagamentoId = formaDePagamentoId;
     FormaDePagamento   = formaDePagamento;
     ValorTotal         = valorTotal;
 }
Example #6
0
        public ClienteDomain Get(int id)
        {
            ClienteDomain retorno = null;

            using (SqlConnection conn = new SqlConnection(SqlConnectionString))
            {
                try
                {
                    conn.Open();

                    using (SqlCommand comm = conn.CreateCommand())
                    {
                        comm.CommandType = CommandType.Text;
                        comm.CommandText = " SELECT * FROM CLIENTE WHERE ID = @ID ";

                        comm.Parameters.Add(new SqlParameter("@ID", id));

                        using (SqlDataReader reader = comm.ExecuteReader())
                        {
                            if (reader.HasRows)
                            {
                                reader.Read();

                                retorno = new ClienteDomain();

                                retorno.Id             = int.Parse(reader["Id"].ToString());
                                retorno.Nome           = reader["Nome"].ToString();
                                retorno.Idade          = short.Parse(reader["Idade"].ToString());
                                retorno.Email          = reader["Email"].ToString();
                                retorno.DataNascimento = DateTime.Parse(reader["DataNascimento"].ToString());
                            }
                        }
                    }

                    return(retorno);
                }
                catch (Exception ex)
                {
                    throw new Exception($"{ex.Message} - {ex.StackTrace}");
                }
                finally
                {
                    conn.Close();
                }
            }
        }
Example #7
0
        public int Update(ClienteDomain model)
        {
            int retorno = 0;

            using (SqlConnection conn = new SqlConnection(SqlConnectionString))
            {
                try
                {
                    conn.Open();

                    using (SqlCommand comm = conn.CreateCommand())
                    {
                        comm.CommandType = CommandType.Text;
                        comm.CommandText = " UPDATE CLIENTE SET NOME=@NOME,IDADE=@IDADE,EMAIL=@EMAIL,DATANASCIMENTO=@DATANASCIMENTO WHERE ID = @ID";

                        comm.Parameters.Add(new SqlParameter("ID", model.Id));
                        comm.Parameters.Add(new SqlParameter("@NOME", model.Nome));
                        comm.Parameters.Add(new SqlParameter("@IDADE", model.Idade));
                        comm.Parameters.Add(new SqlParameter("@EMAIL", model.Email));
                        comm.Parameters.Add(new SqlParameter("@DATANASCIMENTO", model.DataNascimento));

                        retorno = comm.ExecuteNonQuery();
                    }

                    return(retorno);
                }
                catch (Exception ex)
                {
                    throw new Exception($"{ex.Message} - {ex.StackTrace}");
                }
                finally
                {
                    conn.Close();
                }
            }
        }
Example #8
0
        public bool DeleteCliente(int id)
        {
            IClienteDomain domain = new ClienteDomain();

            return(domain.DeleteCliente(id));
        }
Example #9
0
        public Cliente GetCliente(int id)
        {
            IClienteDomain domain = new ClienteDomain();

            return(domain.GetClienteById(id));
        }
 public bool Update(ClienteDomain obj)
 {
     CheckedCliente(obj);
     return(_repository.Update(obj));
 }
 public bool Update(ClienteDomain obj)
 {
     return(_business.Update(obj));
 }
        public long Insert(ClienteDomain obj)
        {
            CheckedCliente(obj);

            return(_repository.Insert(obj));
        }
 public bool Remove(ClienteDomain obj)
 {
     return(_repository.Remove(obj));
 }
Example #14
0
 public VendaBuilder WithCliente(ClienteDomain cliente)
 {
     Cliente = cliente;
     return(this);
 }
 public ProdutoBuilder WithFornecedor(ClienteDomain fornecedor)
 {
     Fornecedor = fornecedor;
     return(this);
 }
 public bool Remove(ClienteDomain obj)
 {
     return(_business.Remove(obj));
 }
Example #17
0
 public IActionResult Cadastrar(ClienteDomain cliente)
 {
     return(Ok(_repo.Inserir(cliente)));
 }
Example #18
0
        public IEnumerable <Cliente> GetClientesAll(string nombre)
        {
            IClienteDomain domain = new ClienteDomain();

            return(domain.GetClientes(nombre));
        }
Example #19
0
 public int Update(ClienteDomain model)
 {
     return(repository.Update(model));
 }
Example #20
0
 public int Insert(ClienteDomain model)
 {
     return(repository.Insert(model));
 }
Example #21
0
 public IActionResult Atualizar(ClienteDomain cliente)
 {
     return(Ok(_repo.Atualizar(cliente)));
 }
Example #22
0
 public IActionResult Inserir([FromBody] ClienteDomain cliente)
 {
     return(Ok(_repo.Inserir(cliente)));
 }
Example #23
0
        public bool SaveCliente(Cliente entity)
        {
            IClienteDomain domain = new ClienteDomain();

            return(domain.SaveCliente(entity));
        }
 public long Insert(ClienteDomain obj)
 {
     return(_business.Insert(obj));
 }