示例#1
0
        public void ChooseAdminOptions(string usFN, string usLN)
        {
            Console.WriteLine("---------------------------");
            Console.WriteLine("Press 1 to add an admin");
            Console.WriteLine("Press 2 to remove an admin");
            Console.WriteLine("Press 3 to add a trainer");
            Console.WriteLine("Press 4 to remove a trainer");
            Console.WriteLine("Press 5 to add a student");
            Console.WriteLine("Press 6 to remove a student");

            try
            {
                int adminResponse = int.Parse(Console.ReadLine());
                if ((adminResponse > 0) || (adminResponse < 7))
                {
                    Console.WriteLine("\n");
                }
                else
                {
                    throw new FormatException("You did not enter a number from 1 to 6!");
                }

                switch (adminResponse)
                {
                case 1:
                    Console.WriteLine("You have chosen to add admin!");
                    Console.WriteLine("Enter admin's first name");
                    string adInpFirst01 = Console.ReadLine().Trim();
                    Console.WriteLine("Enter admin's last name");
                    string adInpLast01 = Console.ReadLine().Trim();
                    Admin  userAdm01   = new Admin(adInpFirst01, adInpLast01);
                    userAdm01.AddAdmin(this.Admins, adInpFirst01, adInpLast01);
                    break;

                case 2:
                    Console.WriteLine("You have chosen to remove an admin!");
                    Console.WriteLine("Enter admin's first name");
                    string adInpFirst02 = Console.ReadLine().Trim();
                    Console.WriteLine("Enter admin's last name");
                    string adInpLast02 = Console.ReadLine().Trim();
                    Admin  userAdm02   = new Admin(adInpFirst02, adInpLast02);
                    if ((adInpFirst02 == usFN) && (adInpLast02 == usLN))
                    {
                        Console.WriteLine("You cannot remove yourself from admin list!");
                    }
                    else
                    {
                        userAdm02.RemoveAdmin(this.Admins, userAdm02);
                        Console.WriteLine("Admin removed!");
                    }
                    break;

                case 3:
                    Console.WriteLine("You have chosen to add a trainer!");
                    Console.WriteLine("Enter trainer's first name");
                    string trInpFirst01 = Console.ReadLine().Trim();
                    Console.WriteLine("Enter trainer's last name");
                    string  trInpLast01 = Console.ReadLine().Trim();
                    Trainer userTr01    = new Trainer(trInpFirst01, trInpLast01);
                    this.currentAdmin.AddTrainer(this.Trainers, trInpFirst01, trInpLast01);
                    break;

                case 4:
                    Console.WriteLine("You have chosen to remove a trainer!");
                    Console.WriteLine("Enter trainer's first name");
                    string trInpFirst02 = Console.ReadLine().Trim();
                    Console.WriteLine("Enter trainer's last name");
                    string  trInpLast02 = Console.ReadLine().Trim();
                    Trainer userTr02    = new Trainer(trInpFirst02, trInpLast02);
                    this.currentAdmin.RemoveTrainer(this.Trainers, userTr02);
                    foreach (var item in this.Trainers)
                    {
                        Console.WriteLine($"{item.GetFullName()}");
                    }
                    break;

                case 5:
                    Console.WriteLine("You have chosen to add a student!");
                    Console.WriteLine("Enter student's first name");
                    string stInpFirst01 = Console.ReadLine().Trim();
                    Console.WriteLine("Enter student's last name");
                    string  stInpLast01 = Console.ReadLine().Trim();
                    Student userSt01    = new Student(stInpFirst01, stInpLast01);
                    this.currentAdmin.AddStudent(this.Students, stInpFirst01, stInpLast01);
                    break;

                case 6:
                    Console.WriteLine("You have chosen to remove a trainer!");
                    Console.WriteLine("Enter student's first name");
                    string stInpFirst02 = Console.ReadLine().Trim();
                    Console.WriteLine("Enter student's last name");
                    string  stInpLast02 = Console.ReadLine().Trim();
                    Student userSt02    = new Student(stInpFirst02, stInpLast02);
                    this.currentAdmin.RemoveStudent(this.Students, userSt02);
                    break;

                default:
                    Console.WriteLine("No such choice offered!");
                    break;
                }
            }
            catch (FormatException ex)
            {
                Console.WriteLine(ex.Message);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
示例#2
0
        public void Start()
        {
            Console.WriteLine("Enter your first name:");
            string userFirstName = Console.ReadLine().Trim();

            Console.WriteLine("Enter your last name:");
            string userLastName = Console.ReadLine().Trim();

            Console.WriteLine($"{userFirstName} {userLastName}, choose your role in the academy: ");

            Console.WriteLine("Press 1 for Admin");
            Console.WriteLine("Press 2 for Trainer");
            Console.WriteLine("Press 3 for Student");
            try
            {
                int userRole = int.Parse(Console.ReadLine());
                if ((userRole == 1) || (userRole == 2) || (userRole == 3))
                {
                    Console.WriteLine("-----------------------------------------");
                }
                else
                {
                    throw new FormatException("You have entered a number different than 1, 2 or 3!");
                }


                switch (userRole)
                {
                //ADMIN CASE OPTIONS------------------------------
                case 1:
                    for (int i = 0; i < this.Admins.Count; i++)
                    {
                        Admin userAdm = new Admin(userFirstName, userLastName);
                        Admin ad;
                        ad = this.Admins[i];

                        if ((ad.FirstName == userAdm.FirstName) && (ad.LastName == userAdm.LastName))
                        {
                            Console.WriteLine("You are one of the admins in the academy!");
                            this.currentAdmin = this.Admins[i];
                            break;
                        }
                        else if ((ad.FirstName != userAdm.FirstName) && (ad.LastName != userAdm.LastName))
                        {
                            Admin newAdm = new Admin(userFirstName, userLastName);
                            this.Admins.Add(newAdm);
                            this.currentAdmin = newAdm;
                            Console.WriteLine("You are added as a new admin in the academy!");
                            break;
                        }
                    }

                    Console.WriteLine($"Welcome admin, {userFirstName} {userLastName}!");
                    Console.WriteLine("-----------------------------------------");

                    ChooseAdminOptions(userFirstName, userLastName);
                    Console.WriteLine("-----------------------------------------");
                    break;

                //TRAINER CASE OPTIONS--------------------------------------
                case 2:
                    for (int i = 0; i < this.Trainers.Count; i++)
                    {
                        Trainer userTr = new Trainer(userFirstName, userLastName);
                        Trainer tr;
                        tr = this.Trainers[i];

                        if ((tr.FirstName == userTr.FirstName) && (tr.LastName == userTr.LastName))
                        {
                            Console.WriteLine("You are one of the trainers in the academy!");
                            break;
                        }
                        else if ((tr.FirstName != userTr.FirstName) && (tr.LastName != userTr.LastName))
                        {
                            Trainer newTr = new Trainer(userFirstName, userLastName);
                            this.Trainers.Add(newTr);
                            Console.WriteLine("You are added as a new trainer in the academy!");
                            break;
                        }
                    }
                    Console.WriteLine($"Welcome trainer, {userFirstName} {userLastName}!");
                    Console.WriteLine("-----------------------------------------");

                    ChooseTrainerOptions();
                    Console.WriteLine("-----------------------------------------");
                    break;

                // STUDENT CASE OPTIONS-----------------------------------
                case 3:
                    for (int i = 0; i < this.Students.Count; i++)
                    {
                        Student userSt = new Student(userFirstName, userLastName);
                        Student st;
                        st = this.Students[i];

                        if ((st.FirstName == userSt.FirstName) && (st.LastName == userSt.LastName))
                        {
                            Console.WriteLine("You are one of the students in the academy!");
                            this.currentStudent = st;
                            break;
                        }
                        else if ((st.FirstName != userSt.FirstName) && (st.LastName != userSt.LastName))
                        {
                            Student newSt = new Student(userFirstName, userLastName);
                            this.Students.Add(newSt);
                            this.currentStudent = newSt;
                            Console.WriteLine("You are added as a new student in the academy! No subjects added yet!");
                            break;
                        }
                    }
                    Console.WriteLine($"Welcome student, {userFirstName} {userLastName}!");
                    Console.WriteLine("-----------------------------------------");

                    ChooseStudentOptions(this.currentStudent);
                    Console.WriteLine("-----------------------------------------");
                    break;

                //DEFAULT OPTION - NO SUCH ROLE ----------------------------
                default:
                    Console.WriteLine("No such role in the academy!");
                    break;
                }
            }
            catch (FormatException ex)
            {
                Console.WriteLine(ex.Message);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
示例#3
0
        static void addTrainer()
        {
            //Defining the variables
            string name;
            int    age;
            string email;
            string subject;

            while ("pigs" != "flying")
            {
                Console.WriteLine("What is your name?");
                name = Console.ReadLine();
                if (name == "")
                {
                    Console.WriteLine("Please enter your name");
                    continue;
                }
                else
                {
                    break;
                }
            }



            //Loop to make sure age is a number
            while ("pigs" != "flying")
            {
                Console.WriteLine("Thank you {0}, what is your age? (As a number please)", name);
                string stringAge = Console.ReadLine();
                //Leaves loop if age is a number
                if (int.TryParse(stringAge, out age))
                {
                    break;
                }
                //Continues if it isn't.
                else
                {
                    Console.WriteLine("Please enter a number");
                    continue;
                }
            }

            while ("pigs" != "flying")
            {
                Console.WriteLine("What is your email? (If none, leave blank)");
                email = Console.ReadLine();
                if (email == "")
                {
                    //Email is allowed to be blank
                    break;
                }
                if (email.Contains("@") && email != "")
                {
                    //Leaves loop if email contains @
                    break;
                }
                else
                {
                    //Email must contain an @ symbol
                    Console.WriteLine("Please enter a valid email address or nothing");
                    continue;
                }
            }

            while ("pigs" != "flying")
            {
                Console.WriteLine("What subject do you teach?");
                subject = Console.ReadLine();

                if (subject != "")
                {
                    break;
                }
                else
                {
                    Console.WriteLine("Please enter a subject");
                    continue;
                }
            }

            Trainer trainer = new Trainer(name, age, email, subject);

            Console.WriteLine("Thank you {0}", trainer.ToString());

            listOfTrainers.Add(trainer);

            foreach (var course in listOfCourses)
            {
                if (course.name == trainer.subject)
                {
                    course.trainers.Add(trainer);
                }
            }
        }