Exemplo n.º 1
0
        public static void Start()
        {
            bool emptyDB = AutoManager.IsEmptyDB();

            if (emptyDB)
            {
                Console.WriteLine("DB is empty, do you want to auto generate? [y/n]");
                string autoGenerate;

                while (true)
                {
                    autoGenerate = Console.ReadLine();
                    if (autoGenerate.Equals("y"))
                    {
                        AutoManager.AutoGenerate();
                        break;
                    }
                    else if (autoGenerate.Equals("n"))
                    {
                        break;
                    }
                    else
                    {
                        continue;
                    }
                }
            }

            bool headMasterExists = AccountManager.HeadMasterExists();

            if (!headMasterExists)
            {
                Console.WriteLine("No head master is present in the database");
                AccountManager.Register();
            }

            bool exit     = false;
            bool loggedIn = false;

            do
            {
                exit = AccountManager.Login(out loggedIn, out string role, out int id);

                if (exit)
                {
                    return;
                }

                if (loggedIn)
                {
                    Console.Clear();
                    switch (role)
                    {
                    case "headmaster":
                        loggedIn = SelectHeadMasterOption();
                        break;

                    case "trainer":
                        loggedIn = SelectTrainerOption(id);
                        break;

                    case "student":
                        loggedIn = SelectStudentOption(id);
                        break;

                    default:
                        Console.WriteLine("i am other");
                        break;
                    }
                }
                else
                {
                    Console.WriteLine("wrong username or password");
                    Console.ReadKey();
                }
            } while (!loggedIn);
        }