From 9ad50398238df7b879b7adf518edfcc3260f4700 Mon Sep 17 00:00:00 2001 From: ivancheahhh Date: Thu, 4 Jan 2024 17:07:36 -0700 Subject: [PATCH] added default values for uploaded file. added validation so that filename is not null in bulk imports. --- Controllers/VehicleController.cs | 6 +++++- Models/Collision/CollisionRecord.cs | 2 +- Models/ServiceRecord/ServiceRecord.cs | 2 +- Models/TaxRecord/TaxRecord.cs | 2 +- Views/Vehicle/_BulkDataImporter.cshtml | 8 +++++++- wwwroot/defaults/servicerecordsample.csv | 3 +++ wwwroot/defaults/taxrecordsample.csv | 3 +++ 7 files changed, 21 insertions(+), 5 deletions(-) create mode 100644 wwwroot/defaults/servicerecordsample.csv create mode 100644 wwwroot/defaults/taxrecordsample.csv diff --git a/Controllers/VehicleController.cs b/Controllers/VehicleController.cs index 82912c5..084a16b 100644 --- a/Controllers/VehicleController.cs +++ b/Controllers/VehicleController.cs @@ -124,8 +124,12 @@ namespace CarCareTracker.Controllers [HttpPost] public IActionResult ImportToVehicleIdFromCsv(int vehicleId, string mode, string fileName) { + if (vehicleId == default || string.IsNullOrWhiteSpace(fileName)) + { + return Json(false); + } var fullFileName = _fileHelper.GetFullFilePath(fileName); - if (vehicleId == default || string.IsNullOrWhiteSpace(fullFileName)) + if (string.IsNullOrWhiteSpace(fullFileName)) { return Json(false); } diff --git a/Models/Collision/CollisionRecord.cs b/Models/Collision/CollisionRecord.cs index ea30cd9..737dee8 100644 --- a/Models/Collision/CollisionRecord.cs +++ b/Models/Collision/CollisionRecord.cs @@ -9,6 +9,6 @@ public string Description { get; set; } public decimal Cost { get; set; } public string Notes { get; set; } - public List Files { get; set; } + public List Files { get; set; } = new List(); } } diff --git a/Models/ServiceRecord/ServiceRecord.cs b/Models/ServiceRecord/ServiceRecord.cs index 30867c6..8a1a449 100644 --- a/Models/ServiceRecord/ServiceRecord.cs +++ b/Models/ServiceRecord/ServiceRecord.cs @@ -9,6 +9,6 @@ public string Description { get; set; } public decimal Cost { get; set; } public string Notes { get; set; } - public List Files { get; set; } + public List Files { get; set; } = new List(); } } diff --git a/Models/TaxRecord/TaxRecord.cs b/Models/TaxRecord/TaxRecord.cs index 615c00e..073695f 100644 --- a/Models/TaxRecord/TaxRecord.cs +++ b/Models/TaxRecord/TaxRecord.cs @@ -8,6 +8,6 @@ public string Description { get; set; } public decimal Cost { get; set; } public string Notes { get; set; } - public List Files { get; set; } + public List Files { get; set; } = new List(); } } diff --git a/Views/Vehicle/_BulkDataImporter.cshtml b/Views/Vehicle/_BulkDataImporter.cshtml index 9a89b23..62a04f0 100644 --- a/Views/Vehicle/_BulkDataImporter.cshtml +++ b/Views/Vehicle/_BulkDataImporter.cshtml @@ -16,9 +16,15 @@ - @if (Model == "gas") + @if (Model == "gasrecord") { Download Sample + } else if (Model == "servicerecord" || Model == "repairrecord") + { + Download Sample + } else if (Model == "taxrecord") + { + Download Sample } diff --git a/wwwroot/defaults/servicerecordsample.csv b/wwwroot/defaults/servicerecordsample.csv new file mode 100644 index 0000000..4e1194e --- /dev/null +++ b/wwwroot/defaults/servicerecordsample.csv @@ -0,0 +1,3 @@ +Date,Odometer,Description,Notes,Cost +01/01/2020,45000,Test Description 1,Test Note 1,20.60 +01/02/2020,47000,Test Description 2,Test Note 2,40.45 \ No newline at end of file diff --git a/wwwroot/defaults/taxrecordsample.csv b/wwwroot/defaults/taxrecordsample.csv new file mode 100644 index 0000000..f6e9a0c --- /dev/null +++ b/wwwroot/defaults/taxrecordsample.csv @@ -0,0 +1,3 @@ +Date,Description,Notes,Cost +01/01/2020,Test Description 1,Test Note 1,20.60 +01/02/2020,Test Description 2,Test Note 2,40.45 \ No newline at end of file