示例#1
0
 public ViewResult Registration(CarRegistration carRegistration)
 {
     if (ModelState.IsValid)
     {
         Repository.AddRegistration(carRegistration);
         return(View("ThankYou", carRegistration));
     }
     else
     {
         return(View());
     }
 }
示例#2
0
        public ParkingEngine()
        {
            //Mocking 5 data entries
            for (int i = 0; i < 5; i++)
            {
                int             counter         = 10 + i;
                string          placeholder     = $"B{counter}FFF";
                CarRegistration carRegistration = new CarRegistration {
                    RegistrationNumber = placeholder, EntryTime = DateTime.UtcNow
                };
                CarRegistrations.Add(carRegistration);
            }

            this.AvailableParkingSpots = 10 - CarRegistrations.Count();
        }
示例#3
0
        public void RegisterCarEntry()
        {
            if (AvailableParkingSpots > 0)
            {
                bool tryAgain;
                do
                {
                    if (!Console.IsOutputRedirected)
                    {
                        Console.Clear();
                    }
                    Console.WriteLine(@"
    ____             _      __                                                      __            
   / __ \___  ____ _(_)____/ /____  _____   ____ _   _________ ______   ___  ____  / /________  __
  / /_/ / _ \/ __ `/ / ___/ __/ _ \/ ___/  / __ `/  / ___/ __ `/ ___/  / _ \/ __ \/ __/ ___/ / / /
 / _, _/  __/ /_/ / (__  ) /_/  __/ /     / /_/ /  / /__/ /_/ / /     /  __/ / / / /_/ /  / /_/ / 
/_/ |_|\___/\__, /_/____/\__/\___/_/      \__,_/   \___/\__,_/_/      \___/_/ /_/\__/_/   \__, /  
           /____/                                                                        /____/   
");

                    Console.Write("Enter The Registration Number: ");
                    string registrationNumber = Console.ReadLine();
                    Console.WriteLine();

                    if (!string.IsNullOrEmpty(registrationNumber) && rg.IsMatch(registrationNumber) && CarRegistrations.SingleOrDefault(car => car.RegistrationNumber == registrationNumber) == null)
                    {
                        CarRegistration carRegistration = new CarRegistration {
                            RegistrationNumber = registrationNumber, EntryTime = DateTime.UtcNow
                        };
                        CarRegistrations.Add(carRegistration);
                        this.AvailableParkingSpots = 10 - CarRegistrations.Count();
                        tryAgain = false;
                        Console.WriteLine("Car Registered Succesfuly!");
                    }
                    else
                    {
                        if (string.IsNullOrEmpty(registrationNumber))
                        {
                            Console.WriteLine("Please enter a Registration Number");
                        }
                        if (!string.IsNullOrEmpty(registrationNumber) && !rg.IsMatch(registrationNumber))
                        {
                            Console.WriteLine("The Registration Number you entered has a wrong format");
                            Console.WriteLine("Please check the spelling and try again");
                        }
                        if (CarRegistrations.SingleOrDefault(car => car.RegistrationNumber == registrationNumber) != null)
                        {
                            Console.WriteLine("The Registration Number is already registered");
                            Console.WriteLine("Please check the spelling and try again");
                        }

                        Console.WriteLine();
                        Console.Write("Try Again? (y/n): ");
                        string answer = Console.ReadLine();

                        if (answer.ToLower() == "y")
                        {
                            tryAgain = true;
                        }
                        else
                        {
                            tryAgain = false;
                        }
                    }
                }while (tryAgain);
            }
            else
            {
                if (!Console.IsOutputRedirected)
                {
                    Console.Clear();
                }
                Console.WriteLine(@"
    ____             _      __                                                      __            
   / __ \___  ____ _(_)____/ /____  _____   ____ _   _________ ______   ___  ____  / /________  __
  / /_/ / _ \/ __ `/ / ___/ __/ _ \/ ___/  / __ `/  / ___/ __ `/ ___/  / _ \/ __ \/ __/ ___/ / / /
 / _, _/  __/ /_/ / (__  ) /_/  __/ /     / /_/ /  / /__/ /_/ / /     /  __/ / / / /_/ /  / /_/ / 
/_/ |_|\___/\__, /_/____/\__/\___/_/      \__,_/   \___/\__,_/_/      \___/_/ /_/\__/_/   \__, /  
           /____/                                                                        /____/   
");
                Console.WriteLine("There are no parking spots available. Please come back later!");
            }

            Console.WriteLine();
            Console.WriteLine("Press Any key to go back to the main menu..");
            Console.ReadLine();
        }