Exemplo n.º 1
0
        private void AddDeveloperToTeam()
        {
            DisplayAllDevs();

            List <DevTeam> listOfDevTeams = _teamRepo.GetDevTeams();

            foreach (DevTeam devTeam in listOfDevTeams)
            {
                Console.WriteLine($"\nTeam Name: {devTeam.DevTeamName.PadRight(15)} ID: {devTeam.DevTeamId}");
            }
            Console.WriteLine("\nChoose a Developer Team ID to add developers to:\n");
            string idAsString = Console.ReadLine();
            var    idAsInt    = int.Parse(idAsString);
            bool   doesExist  = true;

            foreach (DevTeam devTeam1 in listOfDevTeams)
            {
                if (idAsInt != devTeam1.DevTeamId)
                {
                    doesExist = !doesExist;
                }
            }

            if (doesExist)
            {
                DevTeam devTeamOne = _teamRepo.GetTeamById(idAsInt);

                Console.WriteLine("Choose a Developer to add to the Team:\n");
                int teamAsString = int.Parse(Console.ReadLine());
                if (teamAsString == 0)
                {
                    Console.WriteLine("Please try again");
                }
                Developer developer = _devRepo.GetDevById(teamAsString);

                _teamRepo.AddDevsToTeam(developer, devTeamOne);

                bool keepAdding = true;
                while (keepAdding)
                {
                    Console.WriteLine("Add another? Press y/n to continue");
                    string yes = Console.ReadLine().ToLower();

                    if (yes == "y")
                    {
                        DisplayAllDevs();

                        List <DevTeam> listOfDevTeams1 = _teamRepo.GetDevTeams();
                        foreach (DevTeam devTeam in listOfDevTeams1)
                        {
                            Console.WriteLine($"\nTeam Name: {devTeam.DevTeamName}\n" +
                                              $"ID: {devTeam.DevTeamId}");
                        }

                        Console.WriteLine("\nChoose a Developer Team ID to add developers to:\n");
                        string  idAsString1 = Console.ReadLine();
                        int     idAsInt1    = int.Parse(idAsString1);
                        DevTeam devTeamOne1 = _teamRepo.GetTeamById(idAsInt1);

                        Console.WriteLine("Choose a Developer to add to the Team:\n");
                        int       teamAsString1 = int.Parse(Console.ReadLine());
                        Developer developer1    = _devRepo.GetDevById(teamAsString1);

                        _teamRepo.AddDevsToTeam(developer1, devTeamOne1);
                    }
                    else
                    {
                        Console.WriteLine("Press any key to continue");
                        keepAdding = false;
                    }
                }
            }
            else
            {
                Console.WriteLine("Wrong ID. Please try again");
                Thread.Sleep(750); // in miliseconds
            }
        }