예제 #1
0
        /// <summary>
        /// Adds a record to the data source with information provided by the user
        /// </summary>
        /// <param name="skiRunRepository"></param>
        private static void AddSkiRun()
        {
            SkiRunBusiness skiRunBusiness = new SkiRunBusiness(skiRunRepository);
            //Variable Declarations.
            SkiRun aSkiRun = new SkiRun();

            ConsoleView.DisplayReset();

            //Get the ID, Name, and Vertical feet from the user.
            aSkiRun.ID       = ConsoleView.GetIntegerFromUser("Enter the ID for the Ski Run: ");
            aSkiRun.Name     = ConsoleView.GetUserResponse("Enter the name for the Ski Run: ");
            aSkiRun.Vertical = ConsoleView.GetIntegerFromUser("Enter the vertical (in feet) for the Ski Run: ");
            using (skiRunBusiness)
            {
                //Insert the new ski run.
                try
                {
                    //Insert the new record.
                    skiRunRepository.Insert(aSkiRun);

                    //Display a message to the user that the record was inserted.
                    ConsoleView.DisplayReset();
                    ConsoleView.DisplayMessage($"The information for the {aSkiRun.Name} ski run has been saved.");
                    ConsoleView.DisplayContinuePrompt();
                }
                catch (Exception ex)
                {
                    //Display the error message for the error that occurred.
                    CatchIOExceptions(ex);
                }
            }
        }
예제 #2
0
        private void ApplicationControl()
        {
            SkiRunRepository skiRunRepository = new SkiRunRepository();

            ConsoleView.DisplayWelcomeScreen();

            using (skiRunRepository)
            {
                List <SkiRun> skiRuns = skiRunRepository.GetSkiAllRuns();

                while (active)
                {
                    AppEnum.ManagerAction userActionChoice;

                    userActionChoice = ConsoleView.GetUserActionChoice();

                    switch (userActionChoice)
                    {
                    case AppEnum.ManagerAction.None:
                        break;

                    case AppEnum.ManagerAction.ListAllSkiRuns:
                        ConsoleView.DisplayAllSkiRuns(skiRuns);
                        ConsoleView.DisplayContinuePrompt();
                        break;

                    case AppEnum.ManagerAction.DisplaySkiRunDetail:
                        break;

                    case AppEnum.ManagerAction.DeleteSkiRun:
                        //
                        // TODO write a ConsoleView method to get the ski run ID
                        //
                        skiRunRepository.DeleteSkiRun(1);
                        ConsoleView.DisplayReset();
                        ConsoleView.DisplayMessage("Ski Run ID: 1 had been deleted.");
                        ConsoleView.DisplayContinuePrompt();
                        break;

                    case AppEnum.ManagerAction.AddSkiRun:
                        break;

                    case AppEnum.ManagerAction.UpdateSkiRun:
                        break;

                    case AppEnum.ManagerAction.QuerySkiRunsByVertical:
                        break;

                    case AppEnum.ManagerAction.Quit:
                        active = false;
                        break;

                    default:
                        break;
                    }
                }
            }

            ConsoleView.DisplayExitPrompt();
        }
예제 #3
0
        private static void DeleteSkiRun()
        {
            SkiRunRepositoryXML_DS skiRunRepository = new SkiRunRepositoryXML_DS();
            List <SkiRun>          skiRuns;
            SkiRun skiRun = new SkiRun();
            int    skiRunID;
            string message;

            using (skiRunRepository)
            {
                skiRuns = skiRunRepository.SelectAllRuns();
            }

            skiRunID = ConsoleView.GetSkiRunID(skiRuns);

            using (skiRunRepository)
            {
                skiRunRepository.DeleteSkiRun(skiRunID);
            }

            ConsoleView.DisplayReset();

            // TODO refactor
            message = String.Format("Ski Run ID: {0} had been deleted.", skiRunID);

            ConsoleView.DisplayMessage(message);
            ConsoleView.DisplayContinuePrompt();
        }
예제 #4
0
        /// <summary>
        /// Updates a specific ski run's information in the data source with data entered by the user
        /// </summary>
        /// <param name="skiRunRepository"></param>
        /// <param name="skiRuns"></param>
        private static void UpdateSkiRun()
        {
            SkiRunBusiness skiRunBusiness = new SkiRunBusiness(skiRunRepository);
            SkiRun         aSkiRun        = new SkiRun();

            using (skiRunBusiness)
            {
                List <SkiRun> skiRuns = skiRunRepository.SelectAll();
                //Variable Declarations.


                ConsoleView.DisplayReset();

                //Display all ski runs.
                ConsoleView.DisplayAllSkiRuns(skiRuns, false);
                Console.WriteLine();
                Console.WriteLine();

                //Get the information for the ski run to be updated and display it on the screen.
                try
                {
                    //Display the ski run information on the screen.
                    //ConsoleView.DisplaySkiRunDetail(skiRunRepository.GetSkiRunByID(ConsoleView.GetIntegerFromUser("Enter the ID for the Ski Run: ")));
                    aSkiRun = skiRunRepository.SelectById(ConsoleView.GetIntegerFromUser("Enter the ID for the Ski Run: "));
                    ConsoleView.DisplaySkiRunDetail(aSkiRun);
                }
                catch (Exception ex)
                {
                    //Display the error message for the error that occurred.
                    CatchIOExceptions(ex);
                    return;
                }

                //Get the new Name and Vertical feet from the user.
                Console.WriteLine();
                Console.WriteLine();
                aSkiRun.Name     = ConsoleView.GetUserResponse("Enter the new name for the Ski Run: ");
                aSkiRun.Vertical = ConsoleView.GetIntegerFromUser("Enter the new vertical (in feet) for the Ski Run: ");

                //Update the ski run.
                try
                {
                    //Update the ski run information.
                    skiRunRepository.Update(aSkiRun);

                    //Display a message to the user that the record was updated.
                    ConsoleView.DisplayReset();
                    ConsoleView.DisplayMessage($"The information for the {aSkiRun.Name} ski run has been updated.");
                    ConsoleView.DisplayContinuePrompt();
                }
                catch (Exception ex)
                {
                    //Display the error message for the error that occurred.
                    CatchIOExceptions(ex);
                    return;
                }
            }
        }
예제 #5
0
        public static int ValidateIntegerResponse(string promptMessage, string userResponse)
        {
            int userResponseInteger = 0;

            while (!(int.TryParse(userResponse, out userResponseInteger)))
            {
                ConsoleView.DisplayReset();

                ConsoleView.DisplayMessage("");
                ConsoleView.DisplayMessage("It appears you have not entered a valid integer.");

                ConsoleView.DisplayMessage("");
                ConsoleView.DisplayPromptMessage(promptMessage);
                userResponse = Console.ReadLine();
            }


            return(userResponseInteger);
        }
예제 #6
0
        /// <summary>
        /// Displays a list of all ski runs
        /// </summary>
        /// <param name="skiRunRepository"></param>
        private static void DisplaySkiRunDetail()
        {
            SkiRunBusiness skiRunBusiness = new SkiRunBusiness(skiRunRepository);

            ConsoleView.DisplayReset();
            //ConsoleView.DisplayHeader("Display Ski Run Information");
            using (skiRunBusiness)
            {
                try
                {
                    //Display the ski run information on the screen.
                    ConsoleView.DisplaySkiRunDetail(skiRunRepository.SelectById(ConsoleView.GetIntegerFromUser("Enter the ID for the Ski Run: ")));
                    ConsoleView.DisplayContinuePrompt();
                }
                catch (Exception ex)
                {
                    ConsoleView.DisplayErrorMessage(ex.Message);
                    ConsoleView.DisplayContinuePrompt();
                }
            }
        }
예제 #7
0
        private static void DeleteSkiRun()
        {
            SkiRunBusiness skiRunBusiness = new SkiRunBusiness(skiRunRepository);

            List <SkiRun> skiRuns;
            int           skiRunID;
            string        message;

            using (skiRunBusiness)
            {
                skiRuns  = skiRunBusiness.SelectAll();
                skiRunID = ConsoleView.GetSkiRunID(skiRuns);
                skiRunBusiness.Delete(skiRunID);
            }

            ConsoleView.DisplayReset();

            // TODO refactor to confirm
            message = String.Format("Ski Run ID: {0} had been deleted.", skiRunID);

            ConsoleView.DisplayMessage(message);
            ConsoleView.DisplayContinuePrompt();
        }
예제 #8
0
        /// <summary>
        /// Deletes a record from the data source using the ID value entered by the user
        /// </summary>
        /// <param name="skiRunRepository"></param>
        /// <param name="skiRuns"></param>
        private static void DeleteSkiRun()
        {
            SkiRunBusiness skiRunBusiness = new SkiRunBusiness(skiRunRepository);
            List <SkiRun>  skiRuns        = skiRunRepository.SelectAll();
            //Variable declarations.
            int skiRunID = 0;

            //reset display
            ConsoleView.DisplayReset();
            using (skiRunBusiness)
            {
                //Display all ski runs.
                ConsoleView.DisplayAllSkiRuns(skiRuns, false);
                Console.WriteLine();
                Console.WriteLine();

                //Get the ID for the ski run from the user.
                skiRunID = ConsoleView.GetIntegerFromUser("Enter Ski Run ID to delete: ");

                try
                {
                    //Delete the ski run entered.
                    skiRunRepository.Delete(skiRunID);

                    //Display a message to the user that the ski run has been deleted.
                    ConsoleView.DisplayReset();
                    ConsoleView.DisplayMessage($"Ski Run ID: {skiRunID} had been deleted.");
                    ConsoleView.DisplayContinuePrompt();
                }
                catch (Exception ex)
                {
                    //Display the error message for the error that occurred.
                    CatchIOExceptions(ex);
                }
            }
        }
예제 #9
0
        private void ApplicationControl()
        {
            SkiRunRepositoryXML skiRunRepository = new SkiRunRepositoryXML();

            ConsoleView.DisplayWelcomeScreen();

            using (skiRunRepository)
            {
                List <SkiRun> skiRuns = skiRunRepository.GetSkiAllRuns();

                int    skiRunID;
                SkiRun skiRun;
                string message;

                while (active)
                {
                    AppEnum.ManagerAction userActionChoice;

                    userActionChoice = ConsoleView.GetUserActionChoice();

                    switch (userActionChoice)
                    {
                    case AppEnum.ManagerAction.None:
                        break;

                    case AppEnum.ManagerAction.ListAllSkiRuns:
                        ConsoleView.DisplayAllSkiRuns(skiRuns);

                        ConsoleView.DisplayContinuePrompt();
                        break;

                    case AppEnum.ManagerAction.DisplaySkiRunDetail:
                        skiRunID = ConsoleView.GetSkiRunID(skiRuns);
                        skiRun   = skiRunRepository.GetSkiRunByID(skiRunID);

                        ConsoleView.DisplaySkiRun(skiRun);
                        ConsoleView.DisplayContinuePrompt();
                        break;

                    case AppEnum.ManagerAction.AddSkiRun:
                        skiRun = ConsoleView.AddSkiRun();
                        skiRunRepository.InsertSkiRun(skiRun);

                        ConsoleView.DisplayContinuePrompt();
                        break;

                    case AppEnum.ManagerAction.UpdateSkiRun:
                        skiRunID = ConsoleView.GetSkiRunID(skiRuns);
                        skiRun   = skiRunRepository.GetSkiRunByID(skiRunID);

                        skiRun = ConsoleView.UpdateSkiRun(skiRun);

                        skiRunRepository.UpdateSkiRun(skiRun);
                        break;

                    case AppEnum.ManagerAction.DeleteSkiRun:
                        skiRunID = ConsoleView.GetSkiRunID(skiRuns);
                        skiRunRepository.DeleteSkiRun(skiRunID);

                        ConsoleView.DisplayReset();
                        message = String.Format("Ski Run ID: {0} had been deleted.", skiRunID);
                        ConsoleView.DisplayMessage(message);
                        ConsoleView.DisplayContinuePrompt();
                        break;

                    case AppEnum.ManagerAction.QuerySkiRunsByVertical:
                        List <SkiRun> matchingSkiRuns = new List <SkiRun>();

                        int minimumVertical;
                        int maximumVertical;
                        ConsoleView.GetVerticalQueryMinMaxValues(out minimumVertical, out maximumVertical);

                        matchingSkiRuns = skiRunRepository.QueryByVertical(minimumVertical, maximumVertical);

                        ConsoleView.DisplayQueryResults(matchingSkiRuns);
                        ConsoleView.DisplayContinuePrompt();
                        break;

                    case AppEnum.ManagerAction.Quit:
                        active = false;
                        break;

                    default:
                        break;
                    }
                }
            }

            ConsoleView.DisplayExitPrompt();
        }
예제 #10
0
        private void ApplicationControl()
        {
            SkiRunRepository skiRunRepository = new SkiRunRepository();

            ConsoleView.DisplayWelcomeScreen();

            using (skiRunRepository)
            {
                List <SkiRun> skiRuns = skiRunRepository.GetSkiAllRuns();

                while (active)
                {
                    AppEnum.ManagerAction userActionChoice;
                    int           vertical;
                    int           skiRunID;
                    SkiRun        skiRun;
                    string        skiRunString;
                    List <SkiRun> ski2 = new List <SkiRun>();

                    userActionChoice = ConsoleView.GetUserActionChoice();

                    switch (userActionChoice)
                    {
                    case AppEnum.ManagerAction.None:
                        break;

                    case AppEnum.ManagerAction.ListAllSkiRuns:
                        ConsoleView.DisplayAllSkiRuns(skiRuns);
                        ConsoleView.DisplayContinuePrompt();
                        break;

                    case AppEnum.ManagerAction.DisplaySkiRunDetail:
                        ConsoleView.DisplayAllSkiRuns(skiRuns);
                        ski2 = skiRunRepository.GetSkiRunByID(ConsoleView.DisplayGetSkiRunIDChoice(skiRuns));
                        ConsoleView.DisplaySkiRunDetails(ski2);
                        ConsoleView.DisplayContinuePrompt();

                        break;

                    case AppEnum.ManagerAction.DeleteSkiRun:
                        skiRunRepository.DeleteSkiRun(ConsoleView.DisplayGetSkiRunIDChoice(skiRuns));
                        ConsoleView.DisplayReset();
                        ConsoleView.DisplayMessage("Ski Run has been deleted.");
                        ConsoleView.DisplayContinuePrompt();
                        break;

                    case AppEnum.ManagerAction.AddSkiRun:

                        skiRun          = new SkiRun();
                        skiRun.ID       = ConsoleView.DisplayGetSkiRunID();
                        skiRun.Name     = ConsoleView.DisplayGetSkiRunName();
                        skiRun.Vertical = ConsoleView.DisplayGetSkiRunVertical();
                        skiRunRepository.InsertSkiRun(skiRun);
                        ConsoleView.DisplayAllSkiRuns(skiRuns);
                        ConsoleView.DisplayNewSkiRunMessage();

                        break;

                    case AppEnum.ManagerAction.UpdateSkiRun:

                        skiRun    = new SkiRun();
                        skiRun.ID = ConsoleView.DisplayGetSkiRunIDChoice(skiRuns);
                        skiRunRepository.UpdateSkiRun(skiRun);

                        Console.WriteLine();

                        break;

                    case AppEnum.ManagerAction.QuerySkiRunsByVertical:
                        int minimumVertical = skiRunRepository.GetMinimumVertical();
                        int maximumVertical = skiRunRepository.GetMaximumVertical();

                        //Sorts all the available entries and pushes out those that match into a new list.
                        List <SkiRun> matchingSkiRuns = skiRunRepository.QueryByVertical(minimumVertical, maximumVertical);
                        ConsoleView.DisplayReset();

                        //Displays the new list.
                        Console.WriteLine("Ski Runs with a vertical between " + minimumVertical + " and " + maximumVertical + ".");
                        skiRunRepository.DisplayQueriedVertical(matchingSkiRuns);
                        ConsoleView.DisplayContinuePrompt();
                        break;

                    case AppEnum.ManagerAction.Quit:
                        active = false;
                        break;

                    default:
                        break;
                    }
                }
            }

            ConsoleView.DisplayExitPrompt();
        }
예제 #11
0
        private void ApplicationControl()
        {
            SkiRunRepository skiRunRepository = new SkiRunRepository();

            ConsoleView.DisplayWelcomeScreen();

            using (skiRunRepository)
            {
                List <SkiRun> skiRuns = skiRunRepository.GetSkiAllRuns();

                while (active)
                {
                    AppEnum.ManagerAction userActionChoice;

                    int    skiRunID = 1;
                    SkiRun skiRun   = new SkiRun();
                    string message;

                    userActionChoice = ConsoleView.GetUserActionChoice();

                    switch (userActionChoice)
                    {
                    case AppEnum.ManagerAction.None:
                        break;

                    case AppEnum.ManagerAction.ListAllSkiRuns:
                        ConsoleView.DisplayAllSkiRuns(skiRuns);
                        ConsoleView.DisplayContinuePrompt();
                        break;

                    case AppEnum.ManagerAction.DisplaySkiRunDetail:
                        ConsoleView.GetSkiRunID(skiRuns);
                        skiRunRepository.GetSkiRunByID(skiRunID);
                        break;

                    case AppEnum.ManagerAction.DeleteSkiRun:
                        ConsoleView.GetSkiRunID(skiRuns);
                        skiRunRepository.DeleteSkiRun(skiRunID);
                        ConsoleView.DisplayReset();
                        ConsoleView.DisplayMessage($"Ski Run ID:" + skiRunID + "has been deleted.");
                        ConsoleView.DisplayContinuePrompt();
                        break;

                    case AppEnum.ManagerAction.AddSkiRun:
                        ConsoleView.DisplayReset();
                        ConsoleView.GetAddSkiRun(skiRun);
                        skiRunRepository.InsertSkiRun(skiRun);

                        break;

                    case AppEnum.ManagerAction.UpdateSkiRun:
                        break;

                    case AppEnum.ManagerAction.QuerySkiRunsByVertical:

                        break;

                    case AppEnum.ManagerAction.Quit:
                        active = false;
                        break;

                    default:
                        break;
                    }
                }
            }

            ConsoleView.DisplayExitPrompt();
        }