From cb73be0e43ba8e1be778fbabaa15dce3138f4b2d Mon Sep 17 00:00:00 2001 From: "DESKTOP-T0O5CDB\\DESK-555BD" Date: Fri, 12 Jan 2024 14:54:42 -0700 Subject: [PATCH] handle 0 MPG and styling bug fixes. --- Controllers/VehicleController.cs | 7 ++++++- Views/Vehicle/Index.cshtml | 4 ++-- Views/Vehicle/_Report.cshtml | 2 +- wwwroot/js/vehicle.js | 16 ++++++++-------- 4 files changed, 17 insertions(+), 12 deletions(-) diff --git a/Controllers/VehicleController.cs b/Controllers/VehicleController.cs index 981c075..9c81a38 100644 --- a/Controllers/VehicleController.cs +++ b/Controllers/VehicleController.cs @@ -697,7 +697,12 @@ namespace CarCareTracker.Controllers bool useUKMPG = bool.Parse(_config[nameof(UserConfig.UseUKMPG)]); vehicleHistory.TotalGasCost = gasRecords.Sum(x => x.Cost); vehicleHistory.TotalCost = serviceRecords.Sum(x => x.Cost) + repairRecords.Sum(x => x.Cost) + upgradeRecords.Sum(x => x.Cost) + taxRecords.Sum(x => x.Cost); - var averageMPG = _gasHelper.GetGasRecordViewModels(gasRecords, useMPG, useUKMPG).Average(x => x.MilesPerGallon); + var averageMPG = 0.00M; + var gasViewModels = _gasHelper.GetGasRecordViewModels(gasRecords, useMPG, useUKMPG); + if (gasViewModels.Any()) + { + averageMPG = gasViewModels.Average(x => x.MilesPerGallon); + } vehicleHistory.MPG = averageMPG; //insert servicerecords reportData.AddRange(serviceRecords.Select(x => new GenericReportModel diff --git a/Views/Vehicle/Index.cshtml b/Views/Vehicle/Index.cshtml index 784da81..998847e 100644 --- a/Views/Vehicle/Index.cshtml +++ b/Views/Vehicle/Index.cshtml @@ -37,7 +37,7 @@