public void FillSpot(ParkingLot lot, int n, Car car)
 {
     if (n > lot.Spots.Count)
     {
         Console.WriteLine("{0}:{1} does not exist", lot.Lot, n);
     }
     else if (lot.Spots[n - 1].Filled())
     {
         Console.WriteLine("{0}:{1} is currently filled", lot.Lot, n);
     }
     else
     {
         lot.Spots[n - 1].Car = car;
         car.Spot             = lot.Spots[n - 1];
     }
 }
        private void FillRandom(ParkingLot lot)
        {
            Random fill    = new Random();
            Random minutes = new Random();
            Random payType = new Random();
            Random bursar  = new Random();
            Random card    = new Random();
            Random sec     = new Random();

            foreach (ParkingSpot spot in lot.Spots)
            {
                if (fill.Next(0, 100) > 30)
                {
                    var      g    = Guid.NewGuid();
                    var      c    = new Car(g.ToString().Substring(0, 6).ToUpper());
                    DateTime time = DateTime.Now;
                    time        = time.AddMinutes(-minutes.Next(1, 600));
                    c.TimeStamp = time;

                    if (payType.Next(0, 100) > 25)
                    {
                        c.BursarAccount      = new BursarAccount();
                        c.BursarAccount.CWID = 'A' + bursar.Next(10000000, 99999999).ToString();
                        c.BursarAccount.Name = "Jane Doe";
                    }
                    else
                    {
                        c.Card            = new Card();
                        c.Card.CardNumber = card.Next(10000000, 99999999) +
                                            card.Next(10000000, 99999999);
                        c.Card.SecurityNumber = sec.Next(100, 999);
                        c.Card.Name           = "John Doe";
                    }

                    FillSpot(lot, spot.Spot, c);
                }
            }
        }
        public void RunManager()
        {
            //Set up a few base lots for testing purposes.
            List <ParkingLot> lots = new List <ParkingLot>();

            lots.Add(new ParkingLot("A"));
            lots.Add(new ParkingLot("B"));
            lots.Add(new ParkingLot("C"));
            lots.Add(new ParkingLot("D"));
            lots.Add(new ParkingLot("E"));

            //Create spots for each lot of various amounts
            AddSpots(lots[0], 20);
            AddSpots(lots[1], 10);
            AddSpots(lots[2], 38);
            AddSpots(lots[3], 40);
            AddSpots(lots[4], 15);

            //Fill 70~% of the lots with various cars.
            FillRandom(lots[0]);
            FillRandom(lots[1]);
            FillRandom(lots[2]);
            FillRandom(lots[3]);
            FillRandom(lots[4]);

            bool done = false;

            while (!done)
            {
                Console.WriteLine("Are you [p]arking or [g]oing? (exit to exit)");
                switch (Console.ReadLine().ToLower())
                {
                case "parking":
                case "p":
                    Console.WriteLine("Enter your tag number: ");
                    Car myCar = new Car(Console.ReadLine());

                    SetPaymentType(myCar);
                    var openLots = OpenLots(lots);

                    if (!openLots.Any())
                    {
                        Console.WriteLine("No spots are available in any lots");
                        done = true;
                        break;
                    }


                    Console.WriteLine("Open Lots:");
                    foreach (ParkingLot l in openLots)
                    {
                        Console.WriteLine("Lot {0}: {1}", l.Lot, OpenCount(l));
                    }

                    ParkingLot lot   = null;
                    bool       done2 = false;
                    while (!done2)
                    {
                        Console.Write("Select a lot: ");
                        string lotString = Console.ReadLine().ToLower();

                        if (lotString.Equals("exit"))
                        {
                            break;
                        }

                        lot = (lots.Find(A => A.Lot.ToLower().Equals(lotString)));
                        if (lot != null)
                        {
                            done2 = true;
                            break;
                        }

                        Console.WriteLine("Selection invalid.");
                    }


                    if (lot != null)
                    {
                        ParkCar(myCar, lot);
                    }

                    break;

                case "going":
                case "g":
                    Console.WriteLine("Enter your tag number: ");
                    Car leavingCar = FindCar(lots, Console.ReadLine());

                    while (leavingCar == null)
                    {
                        Console.WriteLine("Car not found");
                        Console.WriteLine("Enter your tag number: ");
                        leavingCar = FindCar(lots, Console.ReadLine());
                    }

                    LeaveSpot(leavingCar);
                    ChargeFee(leavingCar, CalcPrice(leavingCar));
                    break;

                case "exit":
                    done = true;
                    break;

                case "print":
                    PrintCars(lots);
                    break;

                default:
                    Console.WriteLine("Please follow the format.");
                    break;
                }
            }
        }
 public int OpenCount(ParkingLot lot)
 {
     return(lot.Spots.Count(A => !A.Filled()));
 }
 public List <ParkingSpot> OpenSpots(ParkingLot lot)
 {
     return(lot.Spots.Where(A => !A.Filled()).ToList());
 }