backend for managing collision records.
This commit is contained in:
@@ -19,6 +19,7 @@ namespace CarCareTracker.Controllers
|
|||||||
private readonly INoteDataAccess _noteDataAccess;
|
private readonly INoteDataAccess _noteDataAccess;
|
||||||
private readonly IServiceRecordDataAccess _serviceRecordDataAccess;
|
private readonly IServiceRecordDataAccess _serviceRecordDataAccess;
|
||||||
private readonly IGasRecordDataAccess _gasRecordDataAccess;
|
private readonly IGasRecordDataAccess _gasRecordDataAccess;
|
||||||
|
private readonly ICollisionRecordDataAccess _collisionRecordDataAccess;
|
||||||
private readonly IWebHostEnvironment _webEnv;
|
private readonly IWebHostEnvironment _webEnv;
|
||||||
private readonly IFileHelper _fileHelper;
|
private readonly IFileHelper _fileHelper;
|
||||||
|
|
||||||
@@ -28,6 +29,7 @@ namespace CarCareTracker.Controllers
|
|||||||
INoteDataAccess noteDataAccess,
|
INoteDataAccess noteDataAccess,
|
||||||
IServiceRecordDataAccess serviceRecordDataAccess,
|
IServiceRecordDataAccess serviceRecordDataAccess,
|
||||||
IGasRecordDataAccess gasRecordDataAccess,
|
IGasRecordDataAccess gasRecordDataAccess,
|
||||||
|
ICollisionRecordDataAccess collisionRecordDataAccess,
|
||||||
IWebHostEnvironment webEnv)
|
IWebHostEnvironment webEnv)
|
||||||
{
|
{
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
@@ -36,6 +38,7 @@ namespace CarCareTracker.Controllers
|
|||||||
_fileHelper = fileHelper;
|
_fileHelper = fileHelper;
|
||||||
_serviceRecordDataAccess = serviceRecordDataAccess;
|
_serviceRecordDataAccess = serviceRecordDataAccess;
|
||||||
_gasRecordDataAccess = gasRecordDataAccess;
|
_gasRecordDataAccess = gasRecordDataAccess;
|
||||||
|
_collisionRecordDataAccess = collisionRecordDataAccess;
|
||||||
_webEnv = webEnv;
|
_webEnv = webEnv;
|
||||||
}
|
}
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
@@ -227,6 +230,50 @@ namespace CarCareTracker.Controllers
|
|||||||
return Json(result);
|
return Json(result);
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
#region "Collision Records"
|
||||||
|
[HttpGet]
|
||||||
|
public IActionResult GetCollisionRecordsByVehicleId(int vehicleId)
|
||||||
|
{
|
||||||
|
var result = _collisionRecordDataAccess.GetCollisionRecordsByVehicleId(vehicleId);
|
||||||
|
return PartialView("_CollisionRecords", result);
|
||||||
|
}
|
||||||
|
[HttpPost]
|
||||||
|
public IActionResult SaveCollisionRecordToVehicleId(CollisionRecordInput serviceRecord)
|
||||||
|
{
|
||||||
|
//move files from temp.
|
||||||
|
serviceRecord.Files = serviceRecord.Files.Select(x => { return new UploadedFiles { Name = x.Name, Location = _fileHelper.MoveFileFromTemp(x.Location, "documents/") }; }).ToList();
|
||||||
|
var result = _collisionRecordDataAccess.SaveCollisionRecordToVehicle(serviceRecord.ToCollisionRecord());
|
||||||
|
return Json(result);
|
||||||
|
}
|
||||||
|
[HttpGet]
|
||||||
|
public IActionResult GetAddCollisionRecordPartialView()
|
||||||
|
{
|
||||||
|
return PartialView("_CollisionRecordModal", new CollisionRecordInput());
|
||||||
|
}
|
||||||
|
[HttpGet]
|
||||||
|
public IActionResult GetCollisionRecordForEditById(int serviceRecordId)
|
||||||
|
{
|
||||||
|
var result = _collisionRecordDataAccess.GetCollisionRecordById(serviceRecordId);
|
||||||
|
//convert to Input object.
|
||||||
|
var convertedResult = new CollisionRecordInput
|
||||||
|
{
|
||||||
|
Id = result.Id,
|
||||||
|
Cost = result.Cost,
|
||||||
|
Date = result.Date.ToShortDateString(),
|
||||||
|
Description = result.Description,
|
||||||
|
Mileage = result.Mileage,
|
||||||
|
Notes = result.Notes,
|
||||||
|
VehicleId = result.VehicleId,
|
||||||
|
Files = result.Files
|
||||||
|
};
|
||||||
|
return PartialView("_CollisionRecordModal", convertedResult);
|
||||||
|
}
|
||||||
|
[HttpPost]
|
||||||
|
public IActionResult DeleteCollisionRecordById(int serviceRecordId)
|
||||||
|
{
|
||||||
|
var result = _collisionRecordDataAccess.DeleteCollisionRecordById(serviceRecordId);
|
||||||
|
return Json(result);
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
56
External/Implementations/CollisionRecordDataAccess.cs
vendored
Normal file
56
External/Implementations/CollisionRecordDataAccess.cs
vendored
Normal file
@@ -0,0 +1,56 @@
|
|||||||
|
using CarCareTracker.External.Interfaces;
|
||||||
|
using CarCareTracker.Models;
|
||||||
|
using LiteDB;
|
||||||
|
|
||||||
|
namespace CarCareTracker.External.Implementations
|
||||||
|
{
|
||||||
|
public class CollisionRecordDataAccess : ICollisionRecordDataAccess
|
||||||
|
{
|
||||||
|
private static string dbName = "cartracker.db";
|
||||||
|
private static string tableName = "collisionrecords";
|
||||||
|
public List<CollisionRecord> GetCollisionRecordsByVehicleId(int vehicleId)
|
||||||
|
{
|
||||||
|
using (var db = new LiteDatabase(dbName))
|
||||||
|
{
|
||||||
|
var table = db.GetCollection<CollisionRecord>(tableName);
|
||||||
|
var collisionRecords = table.Find(Query.EQ(nameof(CollisionRecord.VehicleId), vehicleId)).OrderBy(x => x.Date);
|
||||||
|
return collisionRecords.ToList() ?? new List<CollisionRecord>();
|
||||||
|
};
|
||||||
|
}
|
||||||
|
public CollisionRecord GetCollisionRecordById(int collisionRecordId)
|
||||||
|
{
|
||||||
|
using (var db = new LiteDatabase(dbName))
|
||||||
|
{
|
||||||
|
var table = db.GetCollection<CollisionRecord>(tableName);
|
||||||
|
return table.FindById(collisionRecordId);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
public bool DeleteCollisionRecordById(int collisionRecordId)
|
||||||
|
{
|
||||||
|
using (var db = new LiteDatabase(dbName))
|
||||||
|
{
|
||||||
|
var table = db.GetCollection<CollisionRecord>(tableName);
|
||||||
|
table.Delete(collisionRecordId);
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
public bool SaveCollisionRecordToVehicle(CollisionRecord collisionRecord)
|
||||||
|
{
|
||||||
|
using (var db = new LiteDatabase(dbName))
|
||||||
|
{
|
||||||
|
var table = db.GetCollection<CollisionRecord>(tableName);
|
||||||
|
table.Upsert(collisionRecord);
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
public bool DeleteAllCollisionRecordsByVehicleId(int vehicleId)
|
||||||
|
{
|
||||||
|
using (var db = new LiteDatabase(dbName))
|
||||||
|
{
|
||||||
|
var table = db.GetCollection<CollisionRecord>(tableName);
|
||||||
|
var collisionRecords = table.DeleteMany(Query.EQ(nameof(CollisionRecord.VehicleId), vehicleId));
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
13
External/Interfaces/ICollisionRecordDataAccess.cs
vendored
Normal file
13
External/Interfaces/ICollisionRecordDataAccess.cs
vendored
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
using CarCareTracker.Models;
|
||||||
|
|
||||||
|
namespace CarCareTracker.External.Interfaces
|
||||||
|
{
|
||||||
|
public interface ICollisionRecordDataAccess
|
||||||
|
{
|
||||||
|
public List<CollisionRecord> GetCollisionRecordsByVehicleId(int vehicleId);
|
||||||
|
public CollisionRecord GetCollisionRecordById(int serviceRecordId);
|
||||||
|
public bool DeleteCollisionRecordById(int serviceRecordId);
|
||||||
|
public bool SaveCollisionRecordToVehicle(CollisionRecord serviceRecord);
|
||||||
|
public bool DeleteAllCollisionRecordsByVehicleId(int vehicleId);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -10,6 +10,7 @@ builder.Services.AddSingleton<IVehicleDataAccess, VehicleDataAccess>();
|
|||||||
builder.Services.AddSingleton<INoteDataAccess, NoteDataAccess>();
|
builder.Services.AddSingleton<INoteDataAccess, NoteDataAccess>();
|
||||||
builder.Services.AddSingleton<IServiceRecordDataAccess, ServiceRecordDataAccess>();
|
builder.Services.AddSingleton<IServiceRecordDataAccess, ServiceRecordDataAccess>();
|
||||||
builder.Services.AddSingleton<IGasRecordDataAccess, GasRecordDataAccess>();
|
builder.Services.AddSingleton<IGasRecordDataAccess, GasRecordDataAccess>();
|
||||||
|
builder.Services.AddSingleton<ICollisionRecordDataAccess, CollisionRecordDataAccess>();
|
||||||
builder.Services.AddSingleton<IFileHelper, FileHelper>();
|
builder.Services.AddSingleton<IFileHelper, FileHelper>();
|
||||||
|
|
||||||
var app = builder.Build();
|
var app = builder.Build();
|
||||||
|
|||||||
@@ -1,5 +1,9 @@
|
|||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html lang="en" data-bs-theme="dark">
|
@inject IConfiguration Configuration
|
||||||
|
@{
|
||||||
|
var useDarkMode = bool.Parse(Configuration["DarkMode"]);
|
||||||
|
}
|
||||||
|
<html lang="en" data-bs-theme="@(useDarkMode ? "dark" : "light")">
|
||||||
<head>
|
<head>
|
||||||
<meta charset="utf-8" />
|
<meta charset="utf-8" />
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
ViewData["Title"] = "LubeLogger - View Vehicle";
|
ViewData["Title"] = "LubeLogger - View Vehicle";
|
||||||
}
|
}
|
||||||
@model Vehicle
|
@model Vehicle
|
||||||
@section Scripts{
|
@section Scripts {
|
||||||
<script src="~/js/vehicle.js" asp-append-version="true"></script>
|
<script src="~/js/vehicle.js" asp-append-version="true"></script>
|
||||||
<script src="~/js/servicerecord.js" asp-append-version="true"></script>
|
<script src="~/js/servicerecord.js" asp-append-version="true"></script>
|
||||||
<script src="~/js/gasrecord.js" asp-append-version="true"></script>
|
<script src="~/js/gasrecord.js" asp-append-version="true"></script>
|
||||||
@@ -34,12 +34,15 @@
|
|||||||
<li class="nav-item" role="presentation">
|
<li class="nav-item" role="presentation">
|
||||||
<button class="nav-link" id="notes-tab" data-bs-toggle="tab" data-bs-target="#notes-tab-pane" type="button" role="tab" aria-selected="false"><i class="bi bi-journal-bookmark me-2"></i>Notes</button>
|
<button class="nav-link" id="notes-tab" data-bs-toggle="tab" data-bs-target="#notes-tab-pane" type="button" role="tab" aria-selected="false"><i class="bi bi-journal-bookmark me-2"></i>Notes</button>
|
||||||
</li>
|
</li>
|
||||||
<li class="nav-item ms-auto" role="presentation">
|
<li class="nav-item dropdown ms-auto" role="presentation">
|
||||||
<button class="nav-link" id="manage-tab" data-bs-toggle="tab" data-bs-target="#manage-tab-pane" type="button" role="tab" aria-selected="false"><i class="bi bi-wrench me-2"></i>Manage Vehicle</button>
|
<a class="nav-link dropdown-toggle" data-bs-toggle="dropdown" href="#" role="button" aria-expanded="false">Manage Vehicle</a>
|
||||||
|
<ul class="dropdown-menu">
|
||||||
|
<li><button onclick="deleteVehicle(@Model.Id)" class="dropdown-item"><i class="bi bi-trash me-2"></i>Delete Vehicle</button></li>
|
||||||
|
</ul>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
<div class="tab-content" id="vehicleTabContent">
|
<div class="tab-content" id="vehicleTabContent">
|
||||||
<div class="tab-pane fade show active" id="servicerecord-tab-pane" role="tabpanel"tabindex="0"></div>
|
<div class="tab-pane fade show active" id="servicerecord-tab-pane" role="tabpanel" tabindex="0"></div>
|
||||||
<div class="tab-pane fade" id="gas-tab-pane" role="tabpanel" tabindex="0"></div>
|
<div class="tab-pane fade" id="gas-tab-pane" role="tabpanel" tabindex="0"></div>
|
||||||
<div class="tab-pane fade" id="tax-tab-pane" role="tabpanel" tabindex="0">222</div>
|
<div class="tab-pane fade" id="tax-tab-pane" role="tabpanel" tabindex="0">222</div>
|
||||||
<div class="tab-pane fade" id="notes-tab-pane" role="tabpanel" tabindex="0">
|
<div class="tab-pane fade" id="notes-tab-pane" role="tabpanel" tabindex="0">
|
||||||
@@ -58,13 +61,6 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="tab-pane fade" id="accident-tab-pane" role="tabpanel" tabindex="0">333</div>
|
<div class="tab-pane fade" id="accident-tab-pane" role="tabpanel" tabindex="0">333</div>
|
||||||
<div class="tab-pane fade" id="manage-tab-pane" role="tabpanel" tabindex="0">
|
|
||||||
<div class="row">
|
|
||||||
<div class="d-flex justify-content-center">
|
|
||||||
<button onclick="deleteVehicle(@Model.Id)" class="btn btn-danger btn-md mt-1 mb-1"><i class="bi bi-trash me-2"></i>Delete Vehicle</button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="modal fade" id="editVehicleModal" tabindex="-1" role="dialog">
|
<div class="modal fade" id="editVehicleModal" tabindex="-1" role="dialog">
|
||||||
@@ -74,7 +70,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<script>
|
<script>
|
||||||
function GetVehicleId(){
|
function GetVehicleId() {
|
||||||
return { vehicleId: @Model.Id};
|
return { vehicleId: @Model.Id};
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
@@ -1,3 +1,4 @@
|
|||||||
@using CarCareTracker
|
@using CarCareTracker
|
||||||
@using CarCareTracker.Models
|
@using CarCareTracker.Models
|
||||||
|
@using Microsoft.Extensions.Options
|
||||||
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
|
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
|
||||||
|
|||||||
@@ -5,5 +5,6 @@
|
|||||||
"Microsoft.AspNetCore": "Warning"
|
"Microsoft.AspNetCore": "Warning"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"AllowedHosts": "*"
|
"AllowedHosts": "*",
|
||||||
|
"DarkMode": true
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user