コード例 #1
0
        public UserInput GetSpacePortChoice()
        {
            DisplaySpacePorts();
            Styling.ConsolePrint("\nEnter ID of the SpacePort you would do like to park at: ");
            var spacePort = SpacePortExists(int.Parse(Console.ReadLine()));

            while (spacePort == null || !spacePort.HasAvailableParkingspots() || spacePort.FindFreeParkingSpot(SpaceShip).Count() == 0)
            {
                if (spacePort == null)
                {
                    Styling.ConsolePrint("Sorry that SpacePort doesn't exist.");
                }
                else if (spacePort.FindFreeParkingSpot(SpaceShip).Count() == 0)
                {
                    Styling.ConsolePrint($"{"\nNo suitable parking spot found to support ship length."}");
                }
                else
                {
                    Styling.ConsolePrint("Sorry that SpacePort is closed due to no available spots.");
                }
                Styling.ConsolePrint("\nWhich of our SpacePorts would do like to park at?");
                spacePort = SpacePortExists(int.Parse(Console.ReadLine()));
            }
            SpacePort = spacePort;
            return(this);
        }
コード例 #2
0
        public UserInput GetPersonChoice()
        {
            Styling.ConsolePrint("Enter your SSN:");
            var ssn = Console.ReadLine();
            var personExistsTask = Task.Run(() => Person.EntityExistsInDatabase(ssn));

            new VisualProgressBar().
            AwaitAndShow(new Task[] { personExistsTask })
            .Wait();
            if (!personExistsTask.Result)
            {
                Styling.ConsolePrint("\nEnter your full name: ");
                var name = Console.ReadLine();
                Person.AddEntityToDatabase(ssn, name);
            }
            var personFetchTask = Task.Run(() => Person.GetEntityFromDatabase(ssn));

            new VisualProgressBar().
            AwaitAndShow(new Task[] { personFetchTask })
            .Wait();
            Person = personFetchTask.Result;
            Styling.ConsolePrint("\nWell met, " + Person.Name + ".");
            CheckForUnpaidInvoice();
            return(this);
        }
コード例 #3
0
        static void Main(string[] args)
        {
            Console.ReadLine();
            while (true)
            {
                Console.Clear();
                //Styling.PrintSpaceParkASCIILogo();

                Styling.ConsolePrint("\nWelcome to SpacePark!");

                var userInput = new UserInput()
                                .GetPersonChoice()
                                .GetSpaceShipChoice()
                                .GetSpacePortChoice();

                new ParkingSession()
                .AtSpacePort(userInput.SpacePort)
                .SetForShip(userInput.SpaceShip)
                .ValidateParkingRight(userInput.Person)
                .FindFreeSpot()
                .CreateInvoice()
                .StartParkingSession();

                Console.ReadLine();
            }
        }
コード例 #4
0
        public static CharacterDataRoot SearchCharacterAsync(string search)
        {
            var task = new RestClient("https://swapi.co/api/")
                       .ExecuteAsync <CharacterDataRoot>(
                new RestRequest("people/?search=" + search, DataFormat.Json)
                );

            Styling.InfoPrint("\nWaiting for API response");
            new VisualProgressBar().AwaitAndShow(new Task[] { task }).Wait();
            Styling.InfoPrint("\nResults are in!", 1000);

            return(JsonConvert.DeserializeObject <CharacterDataRoot>(task.Result.Content));
        }
コード例 #5
0
 public ParkingSession CreateInvoice()
 {
     Invoice = new Invoice()
     {
         Paid             = false,
         PersonID         = SpaceShip.DriverPersonID,
         RegistrationTime = DateTime.Now,
         ParkingSpotID    = ParkingSpotID
     };
     Styling.ConsolePrint("\nInvoice created.");
     Invoice.AddEntityToDatabase();
     return(this);
 }
コード例 #6
0
        private void DisplaySpacePorts()
        {
            Styling.ConsolePrint("\nExisting spaceports:");

            using var context = new SpacePortDBContext();
            var spaceports = context.SpacePorts;

            foreach (SpacePort spaceport in spaceports)
            {
                Styling.ConsolePrint($"ID: {spaceport.SpacePortID} " +
                                     $"\tName:  {spaceport.Name.PadRight(14,' ')} " +
                                     $"\tStatus:  {(spaceport.HasAvailableParkingspots() ? "Available Parkingspots" : "Closed")}", 0);
            }
        }
コード例 #7
0
        public ParkingSession FindFreeSpot()
        {
            var parkingSpot = SpacePort.FindFreeParkingSpot(SpaceShip);

            if (parkingSpot.Count() <= 0)
            {
                Styling.ConsolePrint($"{"\nNo suitable parking spot found to support ship length."}");
                Console.ReadLine();
                Environment.Exit(0);
            }
            ParkingSpot          = parkingSpot.First();
            ParkingSpot.Occupied = true;
            ParkingSpotID        = ParkingSpot.ParkingSpotID;
            ParkingSpot.UpdateEntityInDatabase();
            return(this);
        }
コード例 #8
0
 public ParkingSession ValidateParkingRight(Person driver)
 {
     SpaceShip.Driver = driver;
     Styling.ConsolePrint("\nSpacePark is an exclusive SpacePort.\nWe need to run a background check on you.");
     ParkingToken = this.SpaceShip.Driver.IsPartOfStarwars();
     if (ParkingToken)
     {
         Styling.ConsolePrint($"\n{SpaceShip.Driver.Name}, what a pleasure!\nYou have been given an access token to park.");
     }
     else
     {
         Styling.ConsolePrint($"\n{SpaceShip.Driver.Name} sorry SpacePark cannot let you park.");
         Console.ReadLine();
         Environment.Exit(0);
     }
     return(this);
 }
コード例 #9
0
        public UserInput GetSpaceShipChoice()
        {
            if (SpaceShip.EntityExistsInDatabase(Person))
            {
                SpaceShip = SpaceShip.GetEntityFromDatabase(Person);
                Styling.ConsolePrint($"\nGood news! A SpaceShip of {SpaceShip.Length} spacemeters is already registered in your name.");
            }
            else
            {
                Styling.ConsolePrint("\nNo ships registered under your name.");
                string length = String.Empty;
                while (int.TryParse(length, out int result) == false)
                {
                    Styling.ConsolePrint("What's the length of your ship? (In spacemeters please)");
                    length = Console.ReadLine();
                }

                SpaceShip.AddEntityToDatabase(Person, int.Parse(length));
                SpaceShip = SpaceShip.GetEntityFromDatabase(Person);
            }
            return(this);
        }
コード例 #10
0
        private void CheckForUnpaidInvoice()
        {
            Invoice invoice = Invoice.UnpaidInvoiceFromPerson(Person);

            while (invoice != null)
            {
                Styling.ConsolePrint("\nUnpaid invoice detected!");
                Styling.ConsolePrint("Would you like to pay? [Y/N]");

                var userInput = Console.ReadLine();

                if (userInput.ToLower() == "n")
                {
                    CheckForUnpaidInvoice();
                }
                else if (userInput.ToLower() == "y")
                {
                    ParkingSpot.FreeSpotByID(invoice.ParkingSpotID);
                    invoice.Pay(DateTime.Now);
                    return;
                }
            }
        }
コード例 #11
0
 public ParkingSession AtSpacePort(SpacePort port)
 {
     SpacePort = port;
     Styling.ConsolePrint($"Thank you for choosing SpacePort {SpacePort.Name}.");
     return(this);
 }
コード例 #12
0
 public ParkingSession StartParkingSession()
 {
     AddEntityToDatabase();
     Styling.ConsolePrint("\nParking session started");
     return(this);
 }