Esempio n. 1
0
        public async Task <IFluentCustomer> LeavePark(DateTime departureTime)
        {
            parkingTimer.Stop();
            this.ParkingRegistration.DepartureTime = departureTime;
            TimeSpan totalMinutesElapsed = departureTime - this.ParkingRegistration.ArrivalTime;

            TimeSpan elapsedParkingTime = parkingTimer.Elapsed;

            Console.WriteLine("Parkeringstid i verkliga sekunder: " + elapsedParkingTime.Seconds);

            decimal invoiceSum = GateKeeper.CalculateParkingFee(totalMinutesElapsed.TotalHours);

            this.ParkingRegistration.ParkingFee = invoiceSum;

            Console.WriteLine($"Totalparkeringtid: {totalMinutesElapsed.Hours}:{totalMinutesElapsed.Minutes} h");
            Console.WriteLine();

            if (DbAccess.ValidateCustomerCreditWorthiness(ParkingRegistration.CustomerId) == false)
            {
                Console.WriteLine("Du är tvungen att betala kontant för att kunna lämna parkeringen annars beslagtags ditt fordon.");
            }


            var access = new DbAccess();
            await access.SendInvoiceThroughMail(ParkingRegistration.CustomerId);


            Console.WriteLine($"\nPlats {ParkingRegistration.AssignedParkingLotId} är nu ledig igen! ");
            DbAccess.UpdateVacancyInParkinLot(ParkingRegistration.AssignedParkingLotId, false);

            Console.WriteLine($"Just nu är {ParkingHouse.AmountOfEmptylots} platser lediga av totalt {ParkingHouse.TotalParkingsLots}.\n");

            Console.WriteLine();

            DbAccess.AddSingleOrderToDatabase(this.ParkingRegistration);

            return(this);
        }
Esempio n. 2
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);
        }