public static SpaceShip CreateStarshipFromAPI(string url)
        {
            var p        = new SpaceShip();
            var response = ParkingEngine.GetSpaceShipData(url);

            p.Name   = response.Name;
            p.Length = response.Length;

            return(p);
        }
示例#2
0
        public static async Task ClearParkedShip(SpaceShip spaceShip)
        {
            using (var context = new SpaceParkContext())
            {
                // Finds the ship in the person table and set it to null.
                context.ParkingLot.Where(x => x.SpaceShipID == spaceShip.SpaceShipID)
                .FirstOrDefault()
                .SpaceShip = null;

                context.SaveChanges();
            }
        }
示例#3
0
        public static void CheckIn()
        {
            Console.WriteLine("");
            Console.WriteLine("Enter your name:");
            var name = Console.ReadLine();

            // If the person is in starwars and isn't in the database.
            if (ParkingEngine.IsValidPerson(name) && !IsPersonInDatabase(name).Result)
            {
                // Creates the person obejct.
                var person = Person.CreatePersonFromAPI(name);


                // If the person searched is in starwars but has 0 ships.
                if (person.Starships.Count() == 0)
                {
                    Console.WriteLine();
                    Console.WriteLine("You have no ships to park!");
                    Thread.Sleep(2500);
                }

                // If the person has any amount of ships
                else
                {
                    Console.WriteLine("Enter the number of the ship do you want to park:");
                    int count = 0;

                    // Prints all starships associated with person.
                    foreach (var item in person.Starships)
                    {
                        count++;
                        var s = ParkingEngine.GetSpaceShipData(item);

                        Console.WriteLine($"{count}.{s.Name}");
                    }

                    // Saves the users selection.
                    var shipNumber = int.Parse(Console.ReadLine());

                    // Actually creates the ship object.
                    var spaceShip = SpaceShip.CreateStarshipFromAPI(person.Starships[shipNumber - 1]);
                    person.CurrentShip = spaceShip;

                    // Adds the person and ship to the database.
                    ParkingEngine.ParkShip(person);
                }
            }

            else if (!ParkingEngine.IsValidPerson(name))
            {
                Console.WriteLine();
                Console.WriteLine("Sorry you have to have been in Star Wars to park here.");
                Thread.Sleep(2500);
            }

            else
            {
                Console.WriteLine();
                Console.WriteLine("You have already parked here.");
                Thread.Sleep(2500);
            }
        }