diff --git a/CarManagerV3/StateManager.cs b/CarManagerV3/StateManager.cs
index 97b7575..217febe 100644
--- a/CarManagerV3/StateManager.cs
+++ b/CarManagerV3/StateManager.cs
@@ -6,20 +6,44 @@ using System.Threading.Tasks;
namespace CarManagerV3
{
+ // Could be made non-static / non-singleton if multiple collections are needed in the future. Not likely though.
+ ///
+ /// The StateManager class is responsible for managing the state of the car collection, including adding, removing, updating, and retrieving cars.
+ /// Fully static / singleton at the moment, as only one collection is needed.
+ ///
internal class StateManager
{
-
+ // Initialize global static list of cars
static List cars = new List();
+ // Initialize default file path for car data.
+ // TODO: If no recent file paths are found, prompt user to select a file path instead of using a hardcoded default in the program folder.
static string filePath = "cars.csv";
+ ///
+ /// Gets a car by its identifier.
+ ///
+ /// The identifier.
+ ///
+ /// A object if found; otherwise, null.
+ ///
public static Car GetCarById(int id)
{
cars = SafeManager.ReadCars(filePath);
return cars.FirstOrDefault(c => c.Id == id);
}
+ ///
+ /// Public getter and setter for the cars list. Used to have better control over the list.
+ ///
+ ///
+ /// The cars.
+ ///
public static List Cars { get { return cars; } set { cars = value; } }
+ ///
+ /// Adds a car to the collection.
+ ///
+ /// The car to add.
public static void AddCar(Car car)
{
cars = SafeManager.ReadCars(filePath);
@@ -27,6 +51,10 @@ namespace CarManagerV3
SafeManager.SaveCars(filePath, cars);
}
+ ///
+ /// Removes a car from the collection.
+ ///
+ /// The car to remove.
public static void RemoveCar(Car car)
{
cars = SafeManager.ReadCars(filePath);
@@ -36,6 +64,13 @@ namespace CarManagerV3
SafeManager.SaveCars(filePath, cars);
}
+ ///
+ /// Updates a car in the collection. Identifies itself by its Id.
+ ///
+ ///
+ /// If the car's Id has changed during editing, this will not work correctly. Keep Id immutable!
+ ///
+ /// The car to update.
public static void UpdateCar(Car car)
{
Car existingCar = GetCarById(car.Id);
@@ -48,6 +83,18 @@ namespace CarManagerV3
}
}
+ ///
+ /// Creates a new car and adds it to the collection.
+ ///
+ /// The make.
+ /// The model.
+ /// The year.
+ /// The color.
+ /// The mileage.
+ /// The price.
+ ///
+ /// The newly created object.
+ ///
public static Car CreateCar(string make, string model, int year, string color, int mileage, decimal price)
{
cars = SafeManager.ReadCars(filePath);
@@ -57,6 +104,11 @@ namespace CarManagerV3
return newCar;
}
+ ///
+ /// Sets the file path used for saving and loading car data.
+ /// Called when user selects a new file path.
+ ///
+ /// The path.
public static void setFilePath(string path)
{
filePath = path;