Exemple #1
0
        //Add developers and make any other changes to team
        private void AddDevelopersToTeam()
        {
            Console.Clear();
            ViewListOfTeams();
            //Choose team to edit
            Console.WriteLine("\n To which Team would you like to add a developer?");
            string  teamNameString = Console.ReadLine();
            DevTeam team           = new DevTeam();

            //Create a new instance of DevTeam
            Console.WriteLine("Re-enter or update team name: ");                                 //Name
            team.TeamName = Console.ReadLine();
            Console.WriteLine($"Confirm or update Team ID");                                     //ID
            team.TeamID = int.Parse(Console.ReadLine());
            Console.WriteLine($"How many developers would you like to add to {team.TeamName}?"); //Loop for Developers
            int numOfDev             = int.Parse(Console.ReadLine());
            List <Developer> newList = new List <Developer>(numOfDev);

            ViewDevelopers();
            for (int i = 0; i < numOfDev; i++)
            {
                Console.WriteLine($"Enter the badge number of the next developer you wish to add to {team.TeamName}: ");
                int id = int.Parse(Console.ReadLine());

                foreach (Developer dev in _developerRepo._listOfDevelopers)    //code to also add this team to the developer object
                {
                    if (id == dev.BadgeNumber)
                    {
                        dev.Team = team;
                    }
                }

                // Developer next = _developerRepo.GetDeveloper(id);
                newList.Add(_developerRepo.GetDeveloper(id));
            }
            team.TeamMembers = newList;
            _devTeamRepo.UpdateTeam(teamNameString, team);
        }
Exemple #2
0
        //Add developers and make any other changes to team
        private void AddDevelopersToTeam()
        {
            Console.Clear();

            //Choose team to edit


            ViewListOfTeams();
            Console.WriteLine($"Enter the index number of the team you wish to edit.");

            string tempString = (Console.ReadLine());

            int.TryParse(tempString, out int j);

            while (j <= 0 || j > _devTeamRepo._listOfTeams.Count)
            {
                Console.WriteLine("Invalid entry.  Please try again.");

                Console.WriteLine($"Enter the index number of the team you wish to edit.");

                tempString = (Console.ReadLine());
                int.TryParse(tempString, out j);
            }

            DevTeam          team    = new DevTeam();
            List <Developer> newList = new List <Developer>();
            //Create a new instance of DevTeam
            string response;

            _devTeamRepo.TeamDetails(j);
            Console.WriteLine("Do you wish to update team name at this time? y/n");
            response = Console.ReadLine().ToLower();
            if (response == "y")
            {
                Console.WriteLine("What is the new team name: ");  //Name
                team.TeamName = Console.ReadLine();
            }
            else
            {
                string oldName = _devTeamRepo._listOfTeams.ElementAt(j - 1).TeamName;
                team.TeamName = oldName;
            }
            Console.WriteLine($"FYI Team ID cannot be changed.\n"); //ID
            //Loop to add multiple Developers at one time
            string yesOrNo;

            do
            {
                Console.WriteLine($"Would you like to assign developers to {team.TeamName}? y/n");

                yesOrNo = Console.ReadLine().ToLower();
                if (yesOrNo == "y")
                {
                    ViewDevelopers();

                    Console.WriteLine($"How many developers would you like to add to {team.TeamName}?"); //Loop for Developers
                    string tempString2 = (Console.ReadLine());
                    int.TryParse(tempString2, out int k);
                    while (k <= 0 || k > _developerRepo.GetList().Count)
                    {
                        Console.WriteLine("Invalid entry.  Please try again.");

                        Console.WriteLine($"How many developers would you like to add to {team.TeamName}?");
                        tempString2 = Console.ReadLine();
                        int.TryParse(tempString2, out k);
                    }

                    Console.Clear();
                    ViewDevelopers();

                    string x;

                    for (int i = 0; i < k; i++)
                    {
                        Console.WriteLine($"What is the index number of the next developer you would like to add to {team.TeamName}?");
                        x = Console.ReadLine();
                        Developer ex = GetDeveloperByIndex(x);
                        if (ex != null)
                        {
                            if (ex.Team == null)
                            {
                                ex.Team = _devTeamRepo._listOfTeams.ElementAt(j - 1);
                                newList.Add(ex);  //this if statement avoids null exception for the next if...
                            }
                            else
                            if (ex.Team.TeamName == _devTeamRepo._listOfTeams.ElementAt(j - 1).TeamName)
                            {
                                /*catch duplicate dev*/
                                Console.WriteLine("That developer was already assigned and cannot be added again");
                            }
                            else
                            {
                                newList.Add(ex);
                                ex.Team = _devTeamRepo._listOfTeams.ElementAt(j - 1);
                            }
                        }
                        //else continue;
                        while (ex == null)
                        {
                            Console.WriteLine("Invalid input. Try again!\n");



                            x  = Console.ReadLine();
                            ex = GetDeveloperByIndex(x);
                            if (ex != null)
                            {
                                if (ex.Team == null)
                                {
                                    ex.Team = _devTeamRepo._listOfTeams.ElementAt(j - 1);
                                    newList.Add(ex);  //this if statement avoids null exception for the next if...
                                }
                                else
                                if (ex.Team.TeamName == _devTeamRepo._listOfTeams.ElementAt(j - 1).TeamName)
                                {
                                    /*catch duplicate dev*/
                                    Console.WriteLine("That developer was already assigned and cannot be added again");
                                }
                                else
                                {
                                    newList.Add(ex);
                                    ex.Team = _devTeamRepo._listOfTeams.ElementAt(j - 1);
                                }
                            }
                        }
                    }
                    team.TeamMembers = newList;
                }
                else
                if (yesOrNo == "n")
                {
                    break;
                }
                else
                {
                    Console.WriteLine("Please enter y or n.");
                }
            }while (yesOrNo != "y" && yesOrNo != "n");

            if (_devTeamRepo.UpdateTeam(j, team))
            {
                Console.WriteLine("Success");
            }
            else
            {
                Console.WriteLine("Update failed");
            }
        }