Exemple #1
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);
        }
        private void ApplicationControl()
        {
            PetDataRepository petDataRepository = new PetDataRepository();

            ConsoleView.DisplayWelcomeScreen();

            using (petDataRepository)
            {
                List <PetData> petsData = petDataRepository.GetAllPetsDataInfo();

                int     petDataID;
                PetData petData;
                string  message;

                while (active)
                {
                    AppEnum.ManagerAction userActionChoice;

                    userActionChoice = ConsoleView.GetUserActionChoice();

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

                    case AppEnum.ManagerAction.ListAllPetsData:
                        ConsoleView.DisplayAllPetsData(petsData);

                        ConsoleView.DisplayContinuePrompt();
                        break;

                    case AppEnum.ManagerAction.DisplayPetsData:
                        petDataID = ConsoleView.GetPetDataID(petsData);
                        petData   = petDataRepository.GetPetDataByID(petDataID);

                        ConsoleView.DisplayPetData(petData);
                        ConsoleView.DisplayContinuePrompt();
                        break;

                    case AppEnum.ManagerAction.AddPetData:
                        petData = ConsoleView.AddPetData();
                        petDataRepository.InsertPetData(petData);

                        ConsoleView.DisplayContinuePrompt();
                        break;

                    case AppEnum.ManagerAction.UpdatePetData:
                        petDataID = ConsoleView.GetPetDataID(petsData);
                        petData   = petDataRepository.GetPetDataByID(petDataID);

                        ConsoleView.DisplayContinuePrompt();

                        petDataRepository.UpdatePetData(petData);
                        break;

                    case AppEnum.ManagerAction.DeletePetData:
                        petDataID = ConsoleView.GetPetDataID(petsData);
                        petDataRepository.DeletePetData(petDataID);

                        ConsoleView.DisplayReset();
                        message = String.Format("Pet Data ID: {0} had been deleted.", petDataID);
                        ConsoleView.DisplayMessage(message);
                        ConsoleView.DisplayContinuePrompt();
                        break;

                    case AppEnum.ManagerAction.QueryPriceRange:
                        List <PetData> matchingPetsData = new List <PetData>();

                        int minimumPrice;
                        int maximumPrice;
                        ConsoleView.GetPriceQueryMinMaxValues(out minimumPrice, out maximumPrice);

                        matchingPetsData = petDataRepository.QueryPetsDataInformation(minimumPrice, maximumPrice);

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

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

                    default:
                        break;
                    }
                }
            }

            ConsoleView.DisplayExitPrompt();
        }