コード例 #1
0
        public void CheckoutShip(StarWarsPerson pilot)
        {
            var existing = DbUtils.CheckOutCustomer(pilot);
            var fee      = CalculateCheckoutFee(existing);

            Logger.systemLog($"Ship Left The Parkinglot docking fee is {fee}", ConsoleColor.Green);
        }
コード例 #2
0
 public static bool IsDocked(StarWarsPerson person)
 {
     if (person == null)
     {
         throw new ArgumentNullException(nameof(person));
     }
     using var context = new StarWarsDbContext();
     return(context.Person.Any(p => p.Name == person.Name && p.ExitTime == null));
 }
コード例 #3
0
        public static void AddNewCustomerDocking(StarWarsPerson person)
        {
            if (person == null)
            {
                throw new ArgumentNullException(nameof(person));
            }

            using var context = new StarWarsDbContext();
            person.EntryTime  = DateTime.Now;
            context.Person.Add(person);
            context.SaveChanges();
        }
コード例 #4
0
        const int Parkinglotcapacity = 100;  // Macro Substitude
                                             // 26 is the equvilant of 2 default ships (Char 0, Ship 0). used while debuging % for predictibility

        public static void InitiateDialogue(RectangularPlatform parkingDeck)
        {
            parkingDeck.ShowCapacity();

            Console.WriteLine("What's your name?");
            var customerName = Console.ReadLine();

            var customer = ApiUtils.LoadCharacter(customerName);

            var currentPilot = new StarWarsPerson
            {
                Name = customer.Name
            };

            if (DbUtils.IsDocked(currentPilot))
            {
                Logger.ShowSystemErrorText("You already have a ship here, do you want to check it out? Y/N");
                var answer = Console.ReadLine();
                if (answer.ToLower().Contains("y"))
                {
                    parkingDeck.CheckoutShip(currentPilot);
                    return;
                }
            }
            else if (customer.Exists)
            {
                var ship = PickVehicle(customer);
                customer.CurrentShipName = ship.name;
                currentPilot.ShipName    = ship.name;
                currentPilot.Length      = ship.length;

                if (parkingDeck.ShipWillFit(ship.length))
                {
                    if (customer.Wealth > parkingDeck.CalculateDockingFee(ship.length))
                    {
                        parkingDeck.DockShip(currentPilot);
                    }
                    else
                    {
                        Logger.ShowSystemErrorText("Sorry, you can't afford that");
                    }
                }
                else
                {
                    Logger.ShowSystemErrorText("Your ship wont fit");
                }
            }
            else
            {
                Logger.ShowSystemErrorText("You do not have access to this garage");
            }
        }
コード例 #5
0
        public static StarWarsPerson CheckOutCustomer(StarWarsPerson person)
        {
            if (person == null)
            {
                throw new ArgumentNullException(nameof(person));
            }
            using var context = new StarWarsDbContext();
            var item = context.Person.FirstOrDefault(p => p.Name == person.Name && p.ExitTime == null);

            if (item != null)
            {
                item.ExitTime = DateTime.Now;
                context.SaveChanges();
            }

            return(item);
        }
コード例 #6
0
        const int Parkinglotcapacity = 100;  // Macro Substitude
                                             // 26 is the equvilant of 2 default ships (Char 0, Ship 0). used while debuging % for predictibility

        public static async Task InitiateDialogueAsync(RectangularPlatform parkingDeck)
        {
            parkingDeck.ShowCapacity();

            Console.WriteLine("What's your name?");
            var customerName = Console.ReadLine();



            // Connect to DB here while api is loading :desktop:
            //  establishDataBaseConnection();



            Character customer = ApiUtils.LoadCharacter(customerName);


            //Task<Character> taskLoadChar = new Task<Character>(function: () => ApiUtils.LoadCharacter(customerName));

            //Task<List<Ship.Result>> taskLoadShips = new Task<List<Ship.Result>>(function: () => loadAllVehiclesAsync(customer));

            var taskLoadShips = Task.Factory.StartNew(() => loadAllVehiclesAsync(customer));

            //Task<int> taskLoadShips = new Task<int>(function: ()=>loadAllVehiclesAsync(customer));
            //taskLoadShips.Start();

            //System.Console.WriteLine("FROM UI");   // should be called last but appear first. ✔

            var currentPilot = new StarWarsPerson
            {
                Name = customer.Name
            };



            if (DbUtils.IsDocked(currentPilot))
            {
                Logger.systemLog("You already have a ship here, do you want to check it out or swap it for another one? ", ConsoleColor.DarkYellow);
                Logger.systemLog("S = swap, E = check out ", ConsoleColor.DarkYellow);
                string sAnswer = Console.ReadLine();
                //char cAnswer = Console.ReadLine();


                if (sAnswer[0] == 'e' || sAnswer[0] == 'E')
                {
                    parkingDeck.CheckoutShip(currentPilot);
                    return;
                }


                if (sAnswer[0] == 's' || sAnswer[0] == 'S')
                {
                    parkingDeck.CheckoutShip(currentPilot);
                }



                // switch (sAnswer[0])
                // {
                //     case 'e':
                //     case 'E':
                //         parkingDeck.CheckoutShip(currentPilot);
                //         break;
                //
                //     case 's':
                //     case 'S':
                //         parkingDeck.CheckoutShip(currentPilot);
                //         break;
                //
                //     default:
                //         break;
                // }
            }


            if (customer.Exists)
            {
                List <Ship.Result> vShip = await await taskLoadShips; //"await await" <-- intellisense  WTF

                Console.WriteLine();
                Logger.systemLog("Which ship?", ConsoleColor.DarkYellow);


                for (int i = 0; i != vShip.Count; i++)
                {
                    Console.WriteLine(i + " - " + vShip[i].name);
                }
                int iAnswer = Convert.ToInt32(Console.ReadLine());

                Ship.Result ship = new Ship.Result();
                ship = vShip[iAnswer];

                customer.CurrentShipName = ship.name;
                currentPilot.ShipName    = ship.name;
                currentPilot.Length      = ship.length;

                if (parkingDeck.ShipWillFit(ship.length))
                {
                    if (customer.Wealth > parkingDeck.CalculateDockingFee(ship.length))
                    {
                        parkingDeck.DockShip(currentPilot);
                    }

                    else
                    {
                        Logger.systemLog("Sorry, you can't afford that");
                    }
                }

                else
                {
                    Logger.systemLog("Your ship wont fit");
                }
            }
            else
            {
                Logger.systemLog("You do not have access to this garage");
            }
        }
コード例 #7
0
 public void DockShip(StarWarsPerson pilot)
 {
     DbUtils.AddNewCustomerDocking(pilot);
     Logger.systemLog($"Docked Ship: {pilot.ShipName}", ConsoleColor.Green);
 }
コード例 #8
0
        public double CalculateCheckoutFee(StarWarsPerson pilot)
        {
            var timespan = pilot.ExitTime.HasValue ? pilot.ExitTime.Value - pilot.EntryTime : TimeSpan.Zero;

            return(Math.Round((timespan.TotalMinutes / 30)) * 5);
        }