12
I want to edit a record of a client in which I can already register, consult and remove. But I have no idea how to edit just a few items without others being lost.
class Program
{
static List<Cliente> ClienteList = new List<Cliente>();
static void Main(string[] args)
{
int op = -1;
while (op != 0)
{
Console.WriteLine("Digite 1 para cadastrar: ");
Console.WriteLine("Digite 2 para consultar: ");
Console.WriteLine("Digite 3 para remover cadastro");
Console.WriteLine("Digite 4 para editar cadastro: ");
Console.WriteLine("Digite 0 para sair: ");
op = int.Parse(Console.ReadLine());
{
if (op == 1)
{
CadastroCliente();
}
else
if (op == 2)
{
ConsultaCadaCli();
}
else
if (op == 3)
{
RemoverCadastro();
}
else
if (op == 4)
{
EditarCliente();
}
}
}
}
public static void CadastroCliente()
{
Cliente cli = new Cliente();
Console.WriteLine("Digite o nome: ");
cli.Nome = Console.ReadLine();
Console.WriteLine("Digite o CPF: ");
cli.Cpf = int.Parse(Console.ReadLine());
Console.WriteLine("Digite o telefone: ");
cli.Tel = int.Parse(Console.ReadLine());
Console.WriteLine("Digiete o endereco: ");
cli.End = Console.ReadLine();
ClienteList.Add(cli);
}
public static void ConsultaCadaCli()
{
int Consulta;
Console.WriteLine("Digite seu CPF");
Consulta = int.Parse(Console.ReadLine());
var ConsultCadastro = ClienteList.Where(c => c.Cpf.Equals(Consulta)).FirstOrDefault();
if (ConsultCadastro != null)
{
Console.WriteLine("Nome: " + ConsultCadastro.Nome);
Console.WriteLine("CPF: " + ConsultCadastro.Cpf);
Console.WriteLine("Telefone: " + ConsultCadastro.Tel);
Console.WriteLine("Endereco: " + ConsultCadastro.End);
}
else
{
Console.WriteLine("Cliente nao cadastrado");
}
}
public static void RemoverCadastro()
{
int RemCadast;
Console.WriteLine("Digite seu CPF");
RemCadast = int.Parse(Console.ReadLine());
var RCli = ClienteList.Where(r => r.Cpf.Equals(RemCadast)).FirstOrDefault();
if(RCli != null)
{
ClienteList.Remove(RCli);
Console.WriteLine("Cadastro removido com sucesso. ");
}
else
{
Console.WriteLine("Cliente nao cadastrado");
}
}
}
Amanda, I’m already preparing a response and some improvements to your code.
– Pablo Tondolo de Vargas
@Amanda see the [tour]. You can accept one of the answers as the one that helped you the most. And you can vote on all questions and answers you find useful on the entire site, including here.
– Maniero