mirror of
https://github.com/hargata/lubelog.git
synced 2025-12-10 00:46:08 -06:00
46 lines
1.4 KiB
C#
46 lines
1.4 KiB
C#
using CarCareTracker.External.Interfaces;
|
|
using CarCareTracker.Models;
|
|
using LiteDB;
|
|
|
|
namespace CarCareTracker.External.Implementations
|
|
{
|
|
public class VehicleDataAccess: IVehicleDataAccess
|
|
{
|
|
private static string dbName = "cartracker.db";
|
|
private static string tableName = "vehicles";
|
|
public bool SaveVehicle(Vehicle vehicle)
|
|
{
|
|
using (var db = new LiteDatabase(dbName))
|
|
{
|
|
var table = db.GetCollection<Vehicle>(tableName);
|
|
table.Upsert(vehicle);
|
|
return true;
|
|
};
|
|
}
|
|
public bool DeleteVehicle(int vehicleId)
|
|
{
|
|
using (var db = new LiteDatabase(dbName))
|
|
{
|
|
var table = db.GetCollection<Vehicle>(tableName);
|
|
return table.Delete(vehicleId);
|
|
};
|
|
}
|
|
public List<Vehicle> GetVehicles()
|
|
{
|
|
using (var db = new LiteDatabase(dbName))
|
|
{
|
|
var table = db.GetCollection<Vehicle>(tableName);
|
|
return table.FindAll().ToList();
|
|
};
|
|
}
|
|
public Vehicle GetVehicleById(int vehicleId)
|
|
{
|
|
using (var db = new LiteDatabase(dbName))
|
|
{
|
|
var table = db.GetCollection<Vehicle>(tableName);
|
|
return table.FindById(vehicleId);
|
|
};
|
|
}
|
|
}
|
|
}
|