Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            while (true)
            {
                Console.WriteLine("Welcome to our Pet Shelter.");
                Console.WriteLine("To registrate please enter your first name:");
                string firstName = Console.ReadLine();
                Console.WriteLine("Enter your last name:");
                string lastName = Console.ReadLine();
                Console.WriteLine("Enter your city:");
                string city = Console.ReadLine();
                Console.WriteLine("Enter your address:");
                string address = Console.ReadLine();

                Owner newOwner = new Owner(firstName, lastName, city, address);
                _registeredOwner = _ownerService.Register(newOwner);

                Console.Clear();
                Console.WriteLine($"Hello {newOwner.FirstName}. Tell us how old are you?");
                string inputYears = Console.ReadLine();
                int    years;
                bool   inputYearsParsed = Int32.TryParse(inputYears, out years);

                if (_registeredOwner == null || !inputYearsParsed)
                {
                    Console.WriteLine("There has been a problem with the registration! Please try again.");
                    Console.ReadLine();
                    Console.Clear();
                }
                else if (inputYearsParsed && years < 18)
                {
                    Console.WriteLine("Sorry. It seems like you are not old enough to adopt a pet :( .");
                    break;
                }
                else
                {
                    Console.Clear();
                    Console.WriteLine("Cool. You are ready to adopt a pet!");
                    Console.WriteLine(@"This is our list of pets which you can choose from by writing their number and pressing enter. You can adopt multiple pets! Enter ""N"" to stop!");

                    int counter = 1;
                    foreach (Animal animal in _animalService.petShelter)
                    {
                        Console.WriteLine($"{counter}. {animal.Name} the {animal.Specie}");
                        counter++;
                    }

                    string inputNumber = Console.ReadLine();
                    int    number;
                    bool   inputNumberParsed = Int32.TryParse(inputNumber, out number);

                    while (inputNumberParsed)
                    {
                        _adoptedPets = AnimalService.FindPet(_animalService.petShelter, number);

                        if (_adoptedPets != null)
                        {
                            _ownerService.AdoptAnimal(_adoptedPets, _ownerService.Owners[0]);
                        }
                        else if (Console.ReadLine().ToLower() == "n")
                        {
                            Console.WriteLine("Thank you for the adoption!");
                            break;
                        }
                    }
                    break;
                }
            }
        }