コード例 #1
0
        // Create a new DevTeam from user input
        private void CreateNewTeam()
        {
            // Setup
            Console.Clear();
            var devTeam   = new DevTeam();
            var devsToAdd = new List <Developer>();
            var developer = new Developer();

            // Team name
            Console.WriteLine("What is the team's name?");
            devTeam.TeamName = Console.ReadLine();

            // Team ID
EnterTeamID:
            Console.WriteLine("Please enter a unique team ID number.");
            bool parsedTeamID = int.TryParse(Console.ReadLine(), out int teamID);

            if (parsedTeamID)
            {
                foreach (var team in _devTeamRepo.GetAllTeams())
                {
                    if (team.TeamIDNumber == teamID)
                    {
                        Console.WriteLine("Team ID number must be unique. Please try again.");
                        PressAnyKey();
                        goto EnterTeamID;
                    }
                }
                devTeam.TeamIDNumber = teamID;
            }
            else
            {
                PressEnter();
                goto EnterTeamID;
            }

AddDevelopersByID:
            // Team size
            Console.WriteLine("How many developers would you like to add to this team?");
            bool parsedSize = int.TryParse(Console.ReadLine(), out int howManyDevs);

            // Add devs to team
            if (parsedSize)
            {
                for (int x = 1; x <= howManyDevs; x++)
                {
                    Console.WriteLine("Enter the employee ID to add to the team:");
                    bool parsedEmployeeID = int.TryParse(Console.ReadLine(), out int employeeID);
                    if (parsedEmployeeID)
                    {
                        developer = _developerRepo.GetDevByID(employeeID);
                        if (developer != null)
                        {
                            devsToAdd.Add(developer);
                        }
                        else
                        {
                            Console.WriteLine("Employee ID not found. Would you like to add a new employee to this team (y/n)?");
                            string addNew = Console.ReadLine().ToLower();
                            if (addNew == "y")
                            {
                                developer = CreateNewDeveloper();
                                devsToAdd.Add(developer);
                            }
                            else if (addNew == "n")
                            {
                                PressAnyKey();
                                goto AddDevelopersByID;
                            }
                            else
                            {
                                PressEnter();
                                goto AddDevelopersByID;
                            }
                        }
                    }
                    else
                    {
                        PressEnter();
                        goto AddDevelopersByID;
                    }
                }
            }
            else
            {
                PressEnter();
                goto AddDevelopersByID;
            }

            devTeam.TeamMembers = devsToAdd;
            _devTeamRepo.AddNewTeam(devTeam);
        }