Exemplo n.º 1
0
        //Update Existing Team
        private void UpdateTeam()
        {
            Console.Clear();

            //Display all teams
            DisplayAllTeams();

            // Ask for the id to update
            Console.WriteLine("Enter the TeamId of the team you'd like to update:");

            //Get that title
            string teamId    = Console.ReadLine();
            int    teamidint = Convert.ToInt32(teamId);

            //We will build new object
            Console.Clear();
            DevTeam newTeam = new DevTeam();

            //Team Name
            Console.WriteLine("Enter a Team description:");
            newTeam.TeamDescription = Console.ReadLine();


            //Team Active
            Console.WriteLine("Team Active (Y/N):");
            string TeamActive = Console.ReadLine().ToUpper();

            if (TeamActive.Contains("Y"))
            {
                newTeam.TeamActive = true;
            }
            else
            {
                newTeam.TeamActive = false;
            }

            Console.WriteLine("*********LIST OF EMPLOYEES TO ADD**********\n");
            Console.WriteLine("*****THIS WILL MOVE THEM TO NEW TEAM********\n");
            //Build a new list of employees
            List <Developer> _newdeveloperList = new List <Developer>();


            bool KeepAddingDevelopers = true;

            while (KeepAddingDevelopers)
            {
                Console.WriteLine("Select a menu option:\n" +
                                  "1 - Add New Employee to Team by Id\n" +
                                  "2 - End adding developers\n");
                string inputdev = Console.ReadLine();

                switch (inputdev)
                {
                case "1":
                    Console.WriteLine("Enter Employee Id:\n");
                    string employeeId    = Console.ReadLine();
                    bool   EmployeeFound = _developerDirectory.FindDeveloper(employeeId);
                    if (EmployeeFound)
                    {
                        //Find the developer by id
                        Developer developer = _developerDirectory.GetDeveloperById(employeeId);
                        _newdeveloperList.Add(developer);
                    }
                    else
                    {
                        Console.WriteLine($"Employee ID [{employeeId}] not found, try again.");
                    }
                    break;

                case "2":
                    Console.WriteLine("Done adding!");
                    KeepAddingDevelopers = false;
                    break;

                default:
                    Console.WriteLine("Insert a correct value");
                    Console.WriteLine("Please press any key to continue...");
                    Console.ReadKey();
                    break;
                }
            }
            newTeam.Employees = _newdeveloperList;
            bool wasUpdated = _developerTeamRepo.UpdateExistingDevTeam(teamidint, newTeam);

            if (wasUpdated)
            {
                Console.WriteLine("Team was updated successfully.");
            }
            else
            {
                Console.WriteLine("Could not update Team.");
            }
        }