public Car(int ID, int productionYear, int drivenKilometers, string brand, string typeOfCar, decimal price, string placeOfSell, int numberOfDoors, bool isDamaged, Program.FuelTypes fuel) { MyID = ID; ProductionYear = productionYear; DrivenKilometers = drivenKilometers; Brand = brand; TypeOfCar = typeOfCar; Price = price; PlaceOfSell = placeOfSell; NumberOfDoors = numberOfDoors; IsDamaged = isDamaged; Fuel = fuel; }
/* * public void SaveToFile() * { * try * { * if (!File.Exists("CarList.txt")) * { * File.Create("CarList.txt"); * } * else * { * TextWriter writer = new StreamWriter("CarList.txt"); * foreach (KeyValuePair<int, Car> key in _mapOfCars) * { * * Car car = _mapOfCars[key.Key]; * writer.WriteLine($"{car.MyID}\t{car.Brand}\t{car.TypeOfCar}\t{car.ProductionYear}\t{car.DrivenKilometers}\t{car.Price}\t" + * $"{car.PlaceOfSell}\t{car.NumberOfDoors}\t{car.IsDamaged}\t{car.Fuel}"); * * } * writer.Close(); * } * } * catch (Exception e) * { * Console.WriteLine($"Unexpected Error Happend\n" + * $"Error Info:{e.Message}"); * } * } * * public void LoadFromFile() * { * try * { * if (!File.Exists("CarList.txt")) * { * File.Create("CarList.txt"); * * } * else * { * * string[] splitLine; * string[] lines = File.ReadAllLines("CarList.txt"); * foreach (string line in lines) * { * splitLine = line.Split('\t'); * * Car car = carFactory.CreateCarFromFile(Convert.ToInt32(splitLine[0]), Convert.ToInt32(splitLine[3]), Convert.ToInt32(splitLine[4]), splitLine[1], splitLine[2], * Convert.ToDecimal(splitLine[5]), splitLine[6], Convert.ToInt32(splitLine[7]), Convert.ToBoolean(splitLine[8]), * (Program.FuelTypes)Enum.Parse(typeof(Program.FuelTypes), splitLine[9])); * _mapOfCars[car.MyID] = car; * } * } * } * catch (FormatException) * { * Console.WriteLine("Corrupted File"); * Console.ReadLine(); * Console.Clear(); * Console.WriteLine("Reseting File to Default"); * Console.ReadLine(); * Console.Clear(); * File.Delete("CarList.txt"); * File.Create("CarList.txt").Close(); * * Car car = carFactory.CreateCarFromFile(0, 0, 0, "Default Brand of the Car", "Default type of the Car", 0, "Default Place", 0, false, Program.FuelTypes.Diesel); * _mapOfCars.Clear(); * _mapOfCars[car.MyID] = car; * SaveToFile(); * } * catch (Exception e) * { * Console.WriteLine($"Unexpected Error Happend\n" + * $"Error Info:{e.Message}"); * } * * } */ public void AddCarFromKeyboard() { Console.Clear(); Console.WriteLine("Enter year of the production"); int year = CheckYear(); Console.WriteLine("Enter number of kilometers"); int numberOfKilometers = CheckInt(); Console.WriteLine("Enter brand of the car"); string brand = CheckString(); Console.WriteLine("Enter type of the car"); string type = CheckString(); Console.WriteLine("Enter place where you are selling the car"); string placeOfSell = CheckString(); Console.WriteLine("Enter price"); decimal price = CheckDecimal(); Console.WriteLine("Enter number of doors"); int numOfDoors = CheckInt(); Console.WriteLine("Is car damaged? y/n"); bool isDamaged = CheckBoolean(); Console.Write("Choose fuel type:"); foreach (var something in (Program.FuelTypes[])Enum.GetValues(typeof(Program.FuelTypes))) { Console.Write($" {something},"); } Console.WriteLine(); Program.FuelTypes typeOfFuel = CheckFuel(); carFactory.CreateCar(year, numberOfKilometers, brand, type, price, placeOfSell, numOfDoors, isDamaged, typeOfFuel); //Car car = carFactory.CreateCar(year, numberOfKilometers, brand, type, price, placeOfSell, numOfDoors, isDamaged, typeOfFuel); // _mapOfCars[car.MyID] = car; //SaveToFile(); }
public void CreateCar(int ID, int productionYear, int drivenKilometers, string brand, string typeOfCar, decimal price, string placeOfSell, int numberOfDoors, bool isDamaged, Program.FuelTypes fuel) { CarModel car = new CarModel(); car.MyID = ID; car.ProductionYear = productionYear; car.DrivenKilometers = drivenKilometers; car.Brand = brand; car.TypeOfCar = typeOfCar; car.Price = price; car.PlaceOfSell = placeOfSell; car.NumberOfDoors = numberOfDoors; car.IsDamaged = isDamaged; car.Fuel = fuel; repository.AddNewCar(car); }