Ejemplo n.º 1
0
        private void StudentInput(StudentField StudentField)
        {
            ValidatorMessage validatorMessage;
            string           userInput;

            do
            {
                Console.WriteLine($"{StudentField}:");
                userInput = Console.ReadLine();

                if (StudentField == StudentField.FirstName)
                {
                    validatorMessage = validator.ValidateFirstName(userInput);
                }
                else if (StudentField == StudentField.LastName)
                {
                    validatorMessage = validator.ValidateLastName(userInput);
                }
                else if (StudentField == StudentField.Gpa)
                {
                    validatorMessage = validator.ValidateGpa(userInput);
                }
                else
                {
                    return;
                }

                if (validatorMessage.Status)
                {
                    switch (StudentField)
                    {
                    case StudentField.FirstName:
                        student.FirstName = userInput;
                        break;

                    case StudentField.LastName:
                        student.LastName = userInput;
                        break;

                    case StudentField.Gpa:
                        student.Gpa = float.Parse(userInput);
                        break;
                    }
                }
                else
                {
                    DisplayError.Display(validatorMessage.Message);
                }
            } while (validatorMessage.Status != true);
        }
Ejemplo n.º 2
0
        static void Main()
        {
            var runProgram       = true;
            string consoleMenu   = GetConsoleMenu();
            var validator        = new Validator();
            var studentScript    = new StudentScript();

            string userInput;
            ValidatorMessage validation;

            // Run program while runProgram is true 
            while (runProgram)
            {                
                do
                {
                    // Display Console Menu
                    Console.WriteLine(consoleMenu);
                    
                    userInput = Console.ReadLine().ToUpper();

                    // Validate user input against available operations and get ValidatorMessage
                    validation = validator.ValidateOperation(userInput);

                    if (validation.Status)
                    {
                        switch (userInput)
                        {
                            case "ENLIST":
                                studentScript.EnlistStudent(validator);
                                break;
                            case "DISPLAY":
                                studentScript.Display();
                                break;
                            case "EXIT":
                                runProgram = false;
                                break;
                        }
                    }
                    else
                    {
                        DisplayError.Display(validation.Message);
                    }                        

                } while (validation.Status != true);
            }            
        }