-1
The code is available at:Github
I got the Main Class:
static void Main(string[] args)
{
ControleClienteService controleCliente = new ControleClienteService();
controleCliente.CarregarCliente();
ControleConsultaService controleConsulta = new ControleConsultaService();
controleConsulta.CarregarConsulta();
Console.WriteLine("==== Lista de Clientes ====");
Console.WriteLine(controleCliente.Listar());
Console.ReadKey();
break;
}
When I call the controleCliente.Listar()
, he brings the information.
Client class:
public class ControleClienteService
{
private List<Cliente> Clientes;
public bool CadastrarCliente(int qtdCliente, string nome, string endereco, string telefones, string email, string dataNascimento)
{
try
{
Cliente cliente = new Cliente
{
Id = qtdCliente,
Nome = nome,
Endereco = endereco,
Telefones = telefones,
Email = email,
DataNascimento = Convert.ToDateTime(dataNascimento)
};
this.Clientes.Add(cliente);
return true;
}
catch
{
return false;
}
}
public Cliente BuscarClienteId(int id)
{
Cliente cliente = new Cliente();
if (this.Clientes != null)
{
cliente = this.Clientes.Where(x => x.Id == id).FirstOrDefault();
}
return cliente;
}
public bool CarregarCliente()
{
MClientes mClientes = new MClientes();
this.Clientes = mClientes.PreencheClientes();
return true;
}
public string Listar()
{
string retorno = "";
foreach (Cliente C in this.Clientes)
{
retorno += C.Id.ToString() + "\n";
retorno += C.Nome.ToString() + "\n";
retorno += C.DataNascimento.ToString() + "\n";
retorno += C.Telefones.ToString() + "\n";
retorno += C.Endereco.ToString() + "\n";
retorno += " \n";
}
return retorno;
}
Query class:
public class MConsultas
{
List<Consulta> ConsultasClientes = new List<Consulta>();
ControleClienteService ControleCliente = new ControleClienteService();
ControleRestricaoAlimentarService RestricaoAlimentar = new ControleRestricaoAlimentarService();
public List<Consulta> PreencheConsultas()
{
Consulta consulta = new Consulta
{
Id = 23,
Cliente = ControleCliente.BuscarClienteId(23),
RestricoesAlimentares = RestricaoAlimentar.BuscarRestricaoAlimentarId(23),
Hora = Convert.ToDateTime("12:00"),
Peso = 67,
PercenteGordura = 34,
Data = Convert.ToDateTime("19/12/2019")
};
// Adicionar na Lista
ConsultasClientes.Add(consulta);
return ConsultasClientes;
}
}
When you get to the calling part Cliente = ControleCliente.BuscarClienteId(23),
Client class is empty, does not contain values.
The controleConsulta.CarregarConsulta();
You should bring the Customer, however, always the Customer in the code is NULL.
How can I access the Customer, from the query class, equal I access from the Main class?
The estate
Clientes
is filled?– Felipe Avelar
Yeah, I carry her in
ControleClienteService controleCliente = new ControleClienteService();
 controleCliente.CarregarCliente();
&#Both that inConsole.WriteLine(controleCliente.Listar());
It works.Cliente = ControleCliente.BuscarClienteId(23),
Also worked.– Rebeca Nonato
From what I understand of the code, there is no builder for the
ControleClienteService
and you’re not running theCarregarCliente()
in theMConsultas
. So, inside the bootnew Consulta
, where you perform theBuscarClienteId(23)
, the listClientes
is empty, so she’s only returning null...– Felipe Avelar
How to make the Builder for the
ControleClienteService
?– Rebeca Nonato
Just create a method
public NomeDaClasse()
, that it already associates with constructor. You can get more details here– Felipe Avelar
I’ll try to do it here.
– Rebeca Nonato
@Felipeavelar worked, if you want to put as answer. For me to score.
– Rebeca Nonato
You do not need to put "solved" in the title. As the answer below has been accepted (marked with ) this is enough to indicate that it has been solved
– hkotsubo