From 8dfaf49e05160be01eb72362a44e91f86d800c5f Mon Sep 17 00:00:00 2001 From: ivancheahhh Date: Wed, 3 Jan 2024 06:18:39 -0700 Subject: [PATCH] moved more stuff around and gas record functionality. --- Controllers/VehicleController.cs | 14 +++++++++++- Views/Vehicle/Index.cshtml | 3 ++- Views/Vehicle/_Gas.cshtml | 19 ++++++++++------- Views/Vehicle/_ServiceRecords.cshtml | 6 +++--- wwwroot/js/servicerecord.js | 22 ------------------- wwwroot/js/vehicle.js | 32 ++++++++++++++++++++++++++++ 6 files changed, 61 insertions(+), 35 deletions(-) diff --git a/Controllers/VehicleController.cs b/Controllers/VehicleController.cs index 995307f..2fed8c8 100644 --- a/Controllers/VehicleController.cs +++ b/Controllers/VehicleController.cs @@ -115,7 +115,19 @@ namespace CarCareTracker.Controllers } previousMileage = result[i].Mileage; } - return PartialView("_GasRecords", computedResults); + return PartialView("_Gas", computedResults); + } + [HttpPost] + public IActionResult SaveGasRecordToVehicleId(GasRecordInput gasRecord) + { + gasRecord.Files = gasRecord.Files.Select(x => { return new UploadedFiles { Name = x.Name, Location = _fileHelper.MoveFileFromTemp(x.Location, "documents/") }; }).ToList(); + var result = _gasRecordDataAccess.SaveGasRecordToVehicle(gasRecord.ToGasRecord()); + return Json(result); + } + [HttpGet] + public IActionResult GetAddGasRecordPartialView() + { + return PartialView("_GasModal", new GasRecordInput()); } #endregion #region "Service Records" diff --git a/Views/Vehicle/Index.cshtml b/Views/Vehicle/Index.cshtml index 93f37e9..7e90bf7 100644 --- a/Views/Vehicle/Index.cshtml +++ b/Views/Vehicle/Index.cshtml @@ -5,6 +5,7 @@ @section Scripts{ + }
@@ -40,7 +41,7 @@
-
111
+
222
diff --git a/Views/Vehicle/_Gas.cshtml b/Views/Vehicle/_Gas.cshtml index 652cc10..4656a9c 100644 --- a/Views/Vehicle/_Gas.cshtml +++ b/Views/Vehicle/_Gas.cshtml @@ -1,12 +1,15 @@ @model List
-
+
@($"# of Gas Records: {Model.Count()}") - @($"Average Fuel Economy: {Model.Where(y=>y.MilesPerGallon > 0).Average(x => x.MilesPerGallon)}") - @($"Min Fuel Economy: {Model.Min(x => x.MilesPerGallon)}") - @($"Max Fuel Economy: {Model.Max(x => x.MilesPerGallon)}") - @($"Total Gallons: {Model.Sum(x=>x.Gallons)}") + @if (Model.Count() > 1) + { + @($"Average Fuel Economy: {Model.Where(y => y.MilesPerGallon > 0)?.Average(x => x.MilesPerGallon).ToString("F") ?? "0"}") + @($"Min Fuel Economy: {Model.Where(y => y.MilesPerGallon > 0)?.Min(x => x.MilesPerGallon).ToString("F") ?? "0"}") + @($"Max Fuel Economy: {Model.Max(x => x.MilesPerGallon).ToString("F") ?? "0"}") + } + @($"Total Fuel Consumed: {Model.Sum(x=>x.Gallons)}") @($"Total Cost: {Model.Sum(x => x.Cost).ToString("C")}")
@@ -33,10 +36,10 @@ @gasRecord.Date @gasRecord.Mileage - @gasRecord.Gallons - @gasRecord.MilesPerGallon + @gasRecord.Gallons.ToString("F") + @gasRecord.MilesPerGallon.ToString("F") @gasRecord.Cost.ToString("C") - @gasRecord.CostPerGallon + @gasRecord.CostPerGallon.ToString("F") } diff --git a/Views/Vehicle/_ServiceRecords.cshtml b/Views/Vehicle/_ServiceRecords.cshtml index 0441cc4..eb96f24 100644 --- a/Views/Vehicle/_ServiceRecords.cshtml +++ b/Views/Vehicle/_ServiceRecords.cshtml @@ -1,9 +1,9 @@ @model List
-
- @($"Total: {Model.Sum(x=>x.Cost).ToString("C")}") - @($"# of Service Records: {Model.Count()}") +
+ @($"# of Service Records: {Model.Count()}") + @($"Total: {Model.Sum(x => x.Cost).ToString("C")}")
diff --git a/wwwroot/js/servicerecord.js b/wwwroot/js/servicerecord.js index b3bfa7c..34c0c8f 100644 --- a/wwwroot/js/servicerecord.js +++ b/wwwroot/js/servicerecord.js @@ -69,28 +69,6 @@ function saveServiceRecordToVehicle(isEdit) { } }) } -function uploadVehicleFilesAsync(event) { - let formData = new FormData(); - var files = event.files; - for (var x = 0; x < files.length; x++) { - formData.append("file", files[x]); - } - sloader.show(); - $.ajax({ - url: "/Files/HandleMultipleFileUpload", - data: formData, - cache: false, - processData: false, - contentType: false, - type: 'POST', - success: function (response) { - sloader.hide(); - if (response.length > 0) { - uploadedFiles.push.apply(uploadedFiles, response); - } - } - }); -} function getAndValidateServiceRecordValues() { var serviceDate = $("#serviceRecordDate").val(); var serviceMileage = $("#serviceRecordMileage").val(); diff --git a/wwwroot/js/vehicle.js b/wwwroot/js/vehicle.js index d998236..764b062 100644 --- a/wwwroot/js/vehicle.js +++ b/wwwroot/js/vehicle.js @@ -22,6 +22,9 @@ $(document).ready(function () { case "notes-tab": getVehicleNote(vehicleId); break; + case "gas-tab": + getVehicleGasRecords(vehicleId); + break; } switch (e.relatedTarget.id) { //clear out previous tabs with grids in them to help with performance case "servicerecord-tab": @@ -52,4 +55,33 @@ function DeleteVehicle(vehicleId) { window.location.href = '/Home'; } }) +} +function getVehicleGasRecords(vehicleId) { + $.get(`/Vehicle/GetGasRecordsByVehicleId?vehicleId=${vehicleId}`, function (data) { + if (data) { + $("#gas-tab-pane").html(data); + } + }); +} +function uploadVehicleFilesAsync(event) { + let formData = new FormData(); + var files = event.files; + for (var x = 0; x < files.length; x++) { + formData.append("file", files[x]); + } + sloader.show(); + $.ajax({ + url: "/Files/HandleMultipleFileUpload", + data: formData, + cache: false, + processData: false, + contentType: false, + type: 'POST', + success: function (response) { + sloader.hide(); + if (response.length > 0) { + uploadedFiles.push.apply(uploadedFiles, response); + } + } + }); } \ No newline at end of file