Add project files.

This commit is contained in:
Frozd
2025-09-17 13:17:09 +02:00
parent 440e5a1b2b
commit 3561193b2f
22 changed files with 18541 additions and 0 deletions

View File

@@ -0,0 +1,56 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CarManagerV2
{
internal class StateManager
{
static List<Car> cars = new List<Car>();
public static Car getCarById(int id)
{
cars = SafeManager.readCars("cars.csv");
return cars.FirstOrDefault(c => c.Id == id);
}
public static List<Car> Cars { get { return cars; } set { cars = value; } }
public static void addCar(Car car)
{
cars = SafeManager.readCars("cars.csv");
cars.Add(car);
SafeManager.saveCars("cars.csv", cars);
}
public static void removeCar(Car car)
{
cars = SafeManager.readCars("cars.csv");
Console.WriteLine(cars);
cars.Remove(car);
Console.WriteLine(cars);
SafeManager.saveCars("cars.csv", cars);
}
public static void updateCar(Car car)
{
Car existingCar = getCarById(car.Id);
if (existingCar != null)
{
cars.Remove(existingCar);
cars.Add(car);
}
}
public static void createCar(string make, string model, int year, string color, int mileage, decimal price)
{
cars = SafeManager.readCars("cars.csv");
int newId = cars.Count > 0 ? cars.Max(c => c.Id) + 1 : 1;
Car newCar = new Car(newId, make, model, year, color, mileage, price);
cars.Add(newCar);
}
}
}