Esempio n. 1
0
        public async Task <Starship> RegistrateStarship()
        {
            int    index           = 0;
            int    choosenStarship = 0;
            double shipLenght;
            string regNr;

            for (int i = 0; i < 4; i++)
            {
                var objectOfStarships = await CustomerValidator.GetAllStarships(i + 1);

                var ships = objectOfStarships.results;

                Console.WriteLine("\nVar god och registrera ditt rymdskepp.");
                Console.WriteLine("----------------------------------------------------------------------------------------");
                foreach (var ship in ships)
                {
                    const string format = "[{0,2}]{1,50}{2,10}m";

                    index++;
                    Console.WriteLine(string.Format(format, index, ship.name, ship.length));
                }
                Console.WriteLine("----------------------------------------------------------------------------------------\n");
                Console.WriteLine("Bläddra genom nedåt- eller uppåtpilen för att navigera bland förvalda skepp.\n");
                Console.WriteLine("Tryck på enter för att välja skepp.");
                Console.WriteLine( );
                ConsoleKeyInfo keyInfo = Console.ReadKey();

                if (keyInfo.Key == ConsoleKey.DownArrow && i != ships.Count - 1)
                {
                    index = 0;
                    continue;
                }
                else if (keyInfo.Key == ConsoleKey.UpArrow && i != 0)
                {
                    index = 0;
                    i--;
                    continue;
                }
                else if (keyInfo.Key == ConsoleKey.Enter)
                {
                    Console.Write("Välj skepp genom index: ");
                    choosenStarship = int.Parse(Console.ReadLine());
                }
                else
                {
                    index = 0; i = 0; continue;
                }                                    // Default för felnavigering

                string length = ships[choosenStarship - 1].length;
                if (length.Contains(','))
                {
                    length = length.Remove(length.IndexOf(','), 1);
                }

                shipLenght = double.Parse(length, CultureInfo.InvariantCulture);


                if (GateKeeper.IsStarshipToLongForParkinglot(ships[choosenStarship - 1].name, shipLenght) == false)
                {
                    index = 0;
                    i--;
                    continue;
                }


                do
                {
                    Console.WriteLine("Skriv in ditt registreringsnummer: ");
                    regNr = Console.ReadLine();
                } while (GateKeeper.IsRegistrationNumberValid(regNr) == false);


                var newStarship = new Starship(regNr, ships[choosenStarship - 1].name);// Slu7mpa fram ett eget ägarnummer
                return(newStarship);
            }
            return(null);
        }