Example #1
0
 public void Delete(Cliente entity)
 {
     _deleteItems.Add(entity);
 }
Example #2
0
        public Cliente GetById(int pid)
        {
            Cliente cliente = null;
            var sqlQuery = "SELECT c.id_cliente,c.nombre_cliente,c.nombre_persona_contacto, c.correo_electronico, c.telefono, " +
                        "p.id_pais, p.nombre_pais, p.nombre_capital FROM dbo.Clientes c INNER JOIN " +
                      "dbo.Paises p ON c.id_pais = p.id_pais Where c.id_cliente = @idCliente";
            SqlCommand cmd = new SqlCommand();
            cmd.Parameters.AddWithValue("@idCliente", pid);

            var ds = DBAccess.ExecuteSQLWithDS(cmd, sqlQuery);

            if (ds.Tables[0].Rows.Count > 0)
            {
                var dr = ds.Tables[0].Rows[0];

                cliente = new Cliente
                {
                    Id = Convert.ToInt32(dr["id_cliente"]),
                    NombreCliente = dr["nombre_cliente"].ToString(),
                    NombreContacto = dr["nombre_persona_contacto"].ToString(),
                    CorreoElectronico = dr["correo_electronico"].ToString(),
                    Telefono = dr["telefono"].ToString(),
                    IdPais = Convert.ToInt32(dr["id_pais"]),
                    NombrePais = dr["nombre_pais"].ToString(),
                    NombreCapital = dr["nombre_capital"].ToString()
                };
            }
            return cliente;
        }
Example #3
0
        private void InsertCliente(Cliente pcliente)
        {
            try
            {
                SqlCommand cmd = new SqlCommand();

                cmd.Parameters.Add(new SqlParameter("@nombre_cliente", pcliente.NombreCliente));
                cmd.Parameters.Add(new SqlParameter("@nombre_persona_contacto", pcliente.NombreContacto));
                cmd.Parameters.Add(new SqlParameter("@correo_electronico", pcliente.CorreoElectronico));
                cmd.Parameters.Add(new SqlParameter("@telefono", pcliente.Telefono));
                cmd.Parameters.Add(new SqlParameter("@id_pais", pcliente.IdPais));
                DBAccess.ExecuteSPNonQuery(cmd, "USP_Cliente_Insert");

            }
            catch (SqlException ex)
            {
                if (ex.Number == 2601)  // Cannot insert duplicate key row in object error
                {
                    if (ex.Message.Contains("IX_ClientesNombre"))
                    {
                        throw new DataAccessException("Hubo un error al registrar el cliente. El nombre del cliente ya existe.", ex);
                    }
                    else
                    {
                        throw new DataAccessException("Hubo un error al registrar el cliente. El email del cliente ya existe.", ex);
                    }
                }
                else
                {
                    //logear la excepcion a la bd con un Exception
                    throw new DataAccessException("Ha ocurrido un error al registrar un cliente", ex);
                }
            }
            catch (Exception ex)
            {
                //logear la excepcion a la bd con un Exception
                throw new DataAccessException("Ha ocurrido un error al registrar un cliente", ex);
            }
        }
Example #4
0
        private void UpdateCliente(Cliente pcliente)
        {
            try
            {
                SqlCommand cmd = new SqlCommand();
                cmd.Parameters.Add(new SqlParameter("@id_cliente", pcliente.Id));
                cmd.Parameters.Add(new SqlParameter("@nombre_cliente", pcliente.NombreCliente));
                cmd.Parameters.Add(new SqlParameter("@nombre_persona_contacto", pcliente.NombreContacto));
                cmd.Parameters.Add(new SqlParameter("@correo_electronico", pcliente.CorreoElectronico));
                cmd.Parameters.Add(new SqlParameter("@telefono", pcliente.Telefono));
                cmd.Parameters.Add(new SqlParameter("@id_pais", pcliente.IdPais));
                DataSet ds = DBAccess.ExecuteSPWithDS(cmd, "USP_Cliente_Update");

            }
            catch (SqlException ex)
            {
                //logear la excepcion a la bd con un Exception
                throw new DataAccessException("Ha ocurrido un error al modificar un cliente", ex);

            }
            catch (Exception ex)
            {
                //logear la excepcion a la bd con un Exception
                throw new DataAccessException("Ha ocurrido un error al modificar un cliente", ex);
            }
        }
Example #5
0
        private void DeleteCliente(Cliente pcliente)
        {
            try
            {
                SqlCommand cmd = new SqlCommand();
                cmd.Parameters.Add(new SqlParameter("@id_cliente", pcliente.Id));
                DataSet ds = DBAccess.ExecuteSPWithDS(cmd, "USP_Cliente_Delete");

            }
            catch (SqlException ex)
            {
                //logear la excepcion a la bd con un Exception
                throw new DataAccessException("Ha ocurrido un error al eliminar un cliente", ex);

            }
            catch (Exception ex)
            {
                //logear la excepcion a la bd con un Exception
                throw new DataAccessException("Ha ocurrido un error al eliminar un cliente", ex);
            }
        }
Example #6
0
 public void Update(Cliente entity)
 {
     _updateItems.Add(entity);
 }
Example #7
0
 public void Insert(Cliente entity)
 {
     _insertItems.Add(entity);
 }
Example #8
0
 public void eliminarCliente(int pidCliente)
 {
     Cliente cliente = null;
     cliente = new Cliente { Id = pidCliente };
     UoW.ClienteRepository.Delete(cliente);
 }
Example #9
0
        public void registrarCliente(String pnombre, String ppersonacontacto, String pcorreo, String ptelefono, int pidPais)
        {
            Cliente cliente = new Cliente(pnombre,ppersonacontacto,pcorreo,ptelefono,pidPais);
            if (cliente.IsValid)
            {

                UoW.ClienteRepository.Insert(cliente);

            }
            else
            {
                StringBuilder sb = new StringBuilder();
                foreach (RuleViolation rv in cliente.GetRuleViolations())
                {
                    sb.AppendLine(rv.ErrorMessage);
                }
                throw new BusinessLogicException(sb.ToString());
            }
        }