Exemplo n.º 1
0
        // Create Developer
        private void CreateDeveloper()
        {
            Console.Clear();
            // Create new Developer Object
            Developer newDev = new Developer();

            newDev.Id = GetId();
            //Get user input
            Console.WriteLine("Enter the developers name");
            newDev.Name = Console.ReadLine();
            Console.WriteLine("Enter the email");
            newDev.Email = Console.ReadLine();
            Console.WriteLine("Enter the salary (only numbers)");
            newDev.Salary = int.Parse(Console.ReadLine());

            bool needValidInput = true;

            while (needValidInput)
            {
                Console.WriteLine("Do they have access to Pluralsight?(y/n)");
                string hasAccess = Console.ReadLine().ToLower();
                if (hasAccess == "y")
                {
                    newDev.AccessToPluralsight = true;
                    needValidInput             = false;
                }
                else if (hasAccess == "n")
                {
                    newDev.AccessToPluralsight = false;
                    needValidInput             = false;
                }
            }

            _devRepo.AddDeveloper(newDev);
        }
        // Create New Developer
        private void CreateNewDeveloper()
        {
            Console.Clear();

            var newDeveloper = new Developer();


            // Name
            Console.WriteLine("Enter the name of the developer:");
            newDeveloper.Name = Console.ReadLine();
            // Check for empty string
            if (!Input(newDeveloper.Name))
            {
                return;
            }


            // ID Number
            Console.WriteLine($"\nEnter {newDeveloper.Name}'s ID number:");
            string IDasString = Console.ReadLine();

            // Check for empty string
            if (!Input(IDasString))
            {
                return;
            }

            if (IsNum(IDasString))
            {
                newDeveloper.ID = int.Parse(IDasString);
            }
            else
            {
                Console.WriteLine("Sorry, you need to enter a number here.");
                return;
            }



            // Has Access
            Console.WriteLine($"\nDoes {newDeveloper.Name} have access to Pluralsight? (y/n)");
            string hasAccessString = Console.ReadLine().ToLower();

            // Check for empty string
            if (!Input(hasAccessString))
            {
                return;
            }

            if (hasAccessString == "y")
            {
                newDeveloper.HasAccessToPluralsight = true;
            }
            else
            {
                newDeveloper.HasAccessToPluralsight = false;
            }


            // Team Name
            Console.WriteLine($"\nEnter the team name that {newDeveloper.Name} belongs to:");
            string devTeamAsString = Console.ReadLine();

            // Check for empty string
            if (!Input(devTeamAsString))
            {
                return;
            }

            if (_devTeamRepo.GetTeamByName(devTeamAsString) == null)
            {
                DevTeam newDevTeam = new DevTeam(devTeamAsString);
                _devTeamRepo.AddDevTeam(newDevTeam);
            }
            else
            {
                _devTeamRepo.AddDeveloperToTeam(newDeveloper.ID, devTeamAsString);
            }


            _developerRepo.AddDeveloper(newDeveloper);
            _devTeamRepo.AddDeveloperToTeam(newDeveloper.ID, devTeamAsString);
        }