コード例 #1
0
        public static void NovoInstrutor(SortedSet <Aluno> alunos, SortedSet <Instrutor> instrutores, SortedSet <Curso> cursos)
        {
            Console.Write("Digite a id do instrutor: ");
            int  id   = int.Parse(Console.ReadLine());
            bool novo = true;

            foreach (Instrutor instrutor in instrutores)
            {
                if (id == instrutor.Id)
                {
                    Console.WriteLine($"Já existe um instrutor com id {id}");
                    Console.ReadLine();
                    novo = false;
                }
            }
            if (novo)
            {
                Console.Write("Nome do instrutor: ");
                string    nome      = Console.ReadLine();
                Instrutor instrutor = new Instrutor(id, nome);
                instrutores.Add(instrutor);
                char resposta = 's';
                while (resposta == 's')
                {
                    Console.Write("Deseja inscrever o instrutor em algum curso (s/n)? ");
                    resposta = Console.ReadLine()[0];
                    if (resposta == 's')
                    {
                        Console.WriteLine("Cursos disponíveis");
                        foreach (Curso curso in cursos)
                        {
                            Console.WriteLine($"\t{curso.Id}, {curso.Nome}");
                        }
                        Console.Write("Digite a id do curso desejado: ");
                        int  idMatricula = int.Parse(Console.ReadLine());
                        bool matricula   = false;
                        foreach (Curso curso in cursos)
                        {
                            if (idMatricula == curso.Id)
                            {
                                instrutor.AddCursoMinistrado(curso);
                                curso.SetInstrutor(instrutor);
                                matricula = true;
                            }
                        }
                        if (!matricula)
                        {
                            Console.WriteLine("Curso inexistente");
                        }
                        else
                        {
                            instrutor.ConsultaInstrutor();
                        }
                    }
                }
            }
        }