Exemplo n.º 1
0
        static void Main(string[] args)
        {
            InitialSetup();

            var  currentScreen = Screen.StartUp;
            var  userCommand   = UserCommand.None;
            bool isRunning     = true;

            UIPresenter.ShowScreen(currentScreen);

            while (isRunning)
            {
                bool isValid = true;
                do
                {
                    if (isValid)
                    {
                        IOService.Print(Resources.enterYourCommand);
                    }
                    else
                    {
                        IOService.Print(Resources.wrongCommand);
                    }

                    string userInput = Console.ReadLine();
                    isValid = CommandProcessingUnit.GetCommand(userInput, currentScreen, out userCommand);
                } while (!isValid);

                currentScreen = CommandProcessingUnit.ProcessCommand(userCommand, currentScreen);

                UIPresenter.ShowScreen(currentScreen);
            }
            Console.ReadKey();
        }
        /// <summary>
        /// Process inputed command.
        /// </summary>
        /// <param name="userCommand">User command.</param>
        /// <param name="currentScreen">Current screen.</param>
        /// <returns>Screen.</returns>
        public static Screen ProcessCommand(UserCommand userCommand, Screen currentScreen)
        {
            Screen screen = currentScreen;

            switch (userCommand)
            {
            case UserCommand.GoToRegister:
                screen = Screen.Register;
                UIPresenter.ShowScreen(screen);

                if (RegisterProcess())
                {
                    screen = Screen.UserProfile;
                    UIPresenter.ShowScreen(screen);
                }
                else
                {
                    screen = Screen.StartUp;
                    UIPresenter.ShowScreen(screen);
                }
                break;

            case UserCommand.GoToLogin:
                screen = Screen.Login;
                UIPresenter.ShowScreen(screen);

                if (LogInProcess())
                {
                    screen = Screen.UserProfile;
                }
                else
                {
                    screen = Screen.StartUp;
                }
                break;

            case UserCommand.AddToDo:
                screen = Screen.AddToDoScreen;
                UIPresenter.ShowScreen(screen);

                if (AddToList())
                {
                    screen = Screen.UserProfile;
                }
                else
                {
                    screen = Screen.UserProfile;
                }
                break;

            case UserCommand.RemoveToDo:
                RemoveToDo();
                screen = Screen.UserProfile;
                break;

            case UserCommand.CompleteToDo:
                CompleteToDo();
                screen = Screen.UserProfile;
                break;

            case UserCommand.HistoryToDo:
                screen = Screen.HistoryScreen;
                UIPresenter.ShowScreen(screen);
                History();
                screen = Screen.UserProfile;
                break;

            case UserCommand.None:
                break;
            }

            return(screen);
        }