private void RemoveAllCars() { Console.Write("Enter parameter to remove all cars by: "); string parameterToRemove = Console.ReadLine(); switch (parameterToRemove) { case "carType": { CarType carType; bool checkCarType = false; while (!checkCarType) { Console.Write("Enter car type from options: "); Console.WriteLine("\n" + "1.Sedan" + "\n" + "2.Combi" + "\n" + "3.Hatchback" + "\n" + "4.SUV"); Console.WriteLine("-------------------"); string carTypeEntry = Console.ReadLine(); checkCarType = Enum.TryParse(carTypeEntry, out carType); if (checkCarType) { bool carTypeExists = allCarsData.Exists(item => item.CarType == carType); if (carTypeExists) { Guid idCode; var carIdExists = allCarsData.Where(item => item.CarType == carType); foreach (var car in carIdExists) { idCode = car.Id; Bookings toDeleteBooking = null; var reservedResult = reservedCarData.Where(id => id.BookedCar.Id == idCode); if (reservedResult != null) { foreach (var reservation in reservedCarData) { toDeleteBooking = reservation; } reservedCarData.Remove(toDeleteBooking); } } allCarsData.RemoveAll(x => x.CarType == carType); Console.WriteLine("All cars under car type " + carType + " are removed."); Console.WriteLine("-------------------"); } else { Console.WriteLine("There is no such car type!"); } } else { Console.WriteLine("Incorrect parameter!"); continue; } } } break; case "brand": { Console.Write("Enter brand to remove: "); var brand = Console.ReadLine(); bool brandExists = allCarsData.Exists(item => item.Brand == brand); if (brandExists) { Guid idCode; var carIdExists = allCarsData.Where(item => item.Brand == brand); foreach (var car in carIdExists) { idCode = car.Id; Bookings toDeleteBooking = null; var reservedResult = reservedCarData.Where(id => id.BookedCar.Id == idCode); if (reservedResult != null) { foreach (var reservation in reservedCarData) { toDeleteBooking = reservation; } reservedCarData.Remove(toDeleteBooking); } } allCarsData.RemoveAll(x => x.Brand == brand); Console.WriteLine("Cars removed from brand " + brand); } else { Console.WriteLine("There is no such brand!"); } } break; case "model": { Console.Write("Enter model to remove: "); var model = Console.ReadLine(); bool modelExists = allCarsData.Exists(item => item.Model == model); if (modelExists) { Guid idCode; var carIdExists = allCarsData.Where(item => item.Model == model); foreach (var car in carIdExists) { idCode = car.Id; Bookings toDeleteBooking = null; var reservedResult = reservedCarData.Where(id => id.BookedCar.Id == idCode); if (reservedResult != null) { foreach (var reservation in reservedCarData) { toDeleteBooking = reservation; } reservedCarData.Remove(toDeleteBooking); } } allCarsData.RemoveAll(x => x.Model == model); Console.WriteLine("Cars removed from brand " + model); } else { Console.WriteLine("There is no such model!"); } } break; default: { Console.WriteLine($"Parameter {parameterToRemove} has not been recognized."); } break; } }
private void AddReservation(Guid IdCode) { var listOfReservationElements = new Bookings(); string[] command = new string[4]; string idCode = IdCode.ToString(); command[0] = idCode; var commandBookedCarId = Guid.Parse(command[0]); listOfReservationElements.SetBookedCar(commandBookedCarId); DateTime startDate; bool checkDate = false; while (!checkDate) { Console.WriteLine("-------------------"); Console.Write("Enter date: "); command[1] = Console.ReadLine(); checkDate = DateTime.TryParse(command[1], out startDate); if (checkDate) { listOfReservationElements.SetDate(startDate); Console.WriteLine("-------------------"); } else { Console.WriteLine("Incorrect parameter!"); continue; } } Console.Write("Enter client information: "); command[2] = Console.ReadLine(); var commandClientInformation = command[2]; listOfReservationElements.SetClientInformation(commandClientInformation); Console.WriteLine("-------------------"); int period; bool checkPeriod = false; while (!checkPeriod) { Console.Write("Enter period: "); command[3] = Console.ReadLine(); checkPeriod = int.TryParse(command[3], out period); if (checkPeriod) { var pricePerDay = 0; pricePerDay = CalculationOfTotalPrice(period, pricePerDay); var totalPrice = 0; listOfReservationElements.SetRentalInfo(period, pricePerDay, totalPrice); Console.WriteLine($"Period is {period}, price per day is {pricePerDay} and total price totals {period * pricePerDay}."); Console.WriteLine("-------------------"); } else { Console.WriteLine("Incorrect parameter!"); continue; } } reservedCarData.Add(listOfReservationElements); Console.WriteLine("Car has been added to reservation list."); }
private void RemoveCar() { Guid idCode; string idEntry; bool checkId = false; while (!checkId) { Console.WriteLine("-------------------"); Console.Write("Enter car ID: "); idEntry = Console.ReadLine(); checkId = Guid.TryParse(idEntry, out idCode); if (checkId) { Car toDelete = null; Bookings toDeleteBooking = null; var result = allCarsData.Where(x => x.Id == idCode).SingleOrDefault(); var reservedResult = reservedCarData.Where(x => x.BookedCar.Id == idCode).SingleOrDefault(); if (result == null) { Console.WriteLine("There is no such Id of car in the system!"); } else { if (allCarsData.Count != 0) { foreach (var car in allCarsData) { if (car.Id == idCode) { toDelete = car; } else { Console.WriteLine("No such car present!"); } } allCarsData.Remove(toDelete); if (reservedResult != null) { foreach (var reservation in reservedCarData) { toDeleteBooking = reservation; } reservedCarData.Remove(toDeleteBooking); } Console.WriteLine("Car " + idCode + " has been removed."); } else { Console.WriteLine("No cars present in list!"); } } } else { Console.WriteLine("Incorrect parameter!"); continue; } } }