Ejemplo n.º 1
0
        private static void WriteVehiclesToScreen()
        {
            ConsoleWriter.ConsoleHorizontalLine('-');
            Console.WriteLine("YOUR VEHICLES:");
            ConsoleWriter.ConsoleHorizontalLine('-');
            List <string> vehicles = Autobazar.ShowVehicles();

            foreach (var vehicle in vehicles)
            {
                Console.WriteLine(vehicle);
            }
        }
Ejemplo n.º 2
0
        private static void Load()
        {
            Autobazar.LoadVehicles();

            if (Autobazar.GetVehicleCount() == 0)
            {
                Console.WriteLine("There are no vehicles in autobazar.");
            }
            else
            {
                WriteVehiclesToScreen();
            }
        }
Ejemplo n.º 3
0
        private static void Save()
        {
            if (Autobazar.GetVehicleCount() == 0)
            {
                Console.WriteLine("There are no vehicles to save");
            }
            else
            {
                Autobazar.SaveVehicles();

                ConsoleWriter.ConsoleHorizontalLine('-');
                Console.WriteLine("Vehicles were saved.");
            }
        }
Ejemplo n.º 4
0
        static void Main(string[] args)
        {
            try
            {
                Autobazar.LoadVehicles();
            }
            catch
            {
                Console.WriteLine("Error! Something went wrong with loading vehicles.");
                Console.WriteLine("Application will be closed. Press any key.");
                Console.ReadKey();
                return;
            }

            AutobazarMenu.Run();
        }
Ejemplo n.º 5
0
        private static void Add()
        {
            Vehicle vehicle = new Vehicle(Autobazar.GetNextId());

            vehicle.YearOfProduction = InputValidator.GetPositiveNumber("Enter year of production");
            vehicle.NumberOfKm       = InputValidator.GetPositiveNumber("Enter number of km");
            vehicle.VehicleBrand     = InputValidator.GetText("Enter brand of vehicle");
            vehicle.VehicleType      = InputValidator.GetText("Enter type of vehicle");
            vehicle.VehicleFuel      = InputValidator.GetFuel();
            vehicle.Price            = InputValidator.GetPositiveDecimal("Enter price");
            vehicle.City             = InputValidator.GetText("Enter city");
            vehicle.NumberOfDoors    = InputValidator.GetPositiveNumber("Enter number of doors");
            vehicle.IsCrashed        = InputValidator.GetBoolen("Enter if vehicle was crashed - Yes/No");

            Autobazar.AddVehicle(vehicle);

            ConsoleWriter.ConsoleHorizontalLine('-');
            Console.WriteLine("Vehicle was added.");
        }
Ejemplo n.º 6
0
        private static void Edit()
        {
            WriteVehiclesToScreen();

            int     vehicleId = InputValidator.GetPositiveNumber("Enter number of vehicle to edit");
            Vehicle vehicle   = Autobazar.GetVehicleById(vehicleId);

            if (vehicle == null)
            {
                Console.WriteLine("Vehicle not found");
            }
            else
            {
                bool toContinue = true;
                do
                {
                    WriteMenuForEditToScreen();
                    int propertyToEdit = InputValidator.GetNumberFromInterval("Enter number of selected property", 1, 9);

                    vehicle = GetNewData(propertyToEdit, vehicle);

                    bool isError = false;
                    try
                    {
                        Autobazar.EditVehicle(vehicle);
                    }
                    catch (VehicleNotFoundException)
                    {
                        isError = true;
                        Console.WriteLine("Vehicle not found");
                    }

                    if (isError == false)
                    {
                        ConsoleWriter.ConsoleHorizontalLine('-');
                        Console.WriteLine("Vehicle was edited.");
                    }

                    toContinue = InputValidator.GetBoolen($"Something else to edit on vehicle {vehicleId} ? Yes/No");
                } while (toContinue);
            }
        }
Ejemplo n.º 7
0
        private static void Delete()
        {
            WriteVehiclesToScreen();
            int vehicleId = InputValidator.GetPositiveNumber("Enter number of vehicle to delete");

            bool isError = false;

            try
            {
                Autobazar.DeleteVehicle(vehicleId);
            }
            catch (VehicleNotFoundException)
            {
                isError = true;
                Console.WriteLine("Vehicle not found");
            }

            if (isError == false)
            {
                ConsoleWriter.ConsoleHorizontalLine('-');
                Console.WriteLine("Vehicle was deleted.");
            }
        }