diff --git a/Controllers/VehicleController.cs b/Controllers/VehicleController.cs index 2409534..2fcfff4 100644 --- a/Controllers/VehicleController.cs +++ b/Controllers/VehicleController.cs @@ -2,16 +2,9 @@ using CarCareTracker.External.Interfaces; using CarCareTracker.Models; using LiteDB; using Microsoft.AspNetCore.Mvc; -using System.Diagnostics; -using static System.Net.Mime.MediaTypeNames; -using System.Drawing; -using System.Linq.Expressions; -using Microsoft.Extensions.Logging; -using CarCareTracker.External.Implementations; using CarCareTracker.Helper; using CsvHelper; using System.Globalization; -using System.Runtime.InteropServices; namespace CarCareTracker.Controllers { @@ -415,10 +408,19 @@ namespace CarCareTracker.Controllers }; return PartialView("_CostMakeUpReport", viewModel); } - //public IActionResult GetFuelCostByMonthByVehicle(int vehicleId) - //{ - - //} + public IActionResult GetFuelCostByMonthByVehicle(int vehicleId, int year = 0) + { + var gasRecords = _gasRecordDataAccess.GetGasRecordsByVehicleId(vehicleId); + if (year != default) + { + gasRecords.RemoveAll(x => x.Date.Year != year); + } + var groupedGasRecord = gasRecords.GroupBy(x => x.Date.Month).OrderBy(x=>x.Key).Select(x => new GasCostForVehicleByMonth { + MonthName = CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(x.Key), + Cost = x.Sum(y=>y.Cost) + }).ToList(); + return PartialView("_GasCostByMonthReport", groupedGasRecord); + } #endregion } } diff --git a/Models/Report/GasCostForVehicleByMonth.cs b/Models/Report/GasCostForVehicleByMonth.cs new file mode 100644 index 0000000..fd93ece --- /dev/null +++ b/Models/Report/GasCostForVehicleByMonth.cs @@ -0,0 +1,8 @@ +namespace CarCareTracker.Models +{ + public class GasCostForVehicleByMonth + { + public string MonthName { get; set; } + public decimal Cost { get; set; } + } +} diff --git a/Views/Vehicle/_CostMakeUpReport.cshtml b/Views/Vehicle/_CostMakeUpReport.cshtml index 5141e66..4bb252e 100644 --- a/Views/Vehicle/_CostMakeUpReport.cshtml +++ b/Views/Vehicle/_CostMakeUpReport.cshtml @@ -1,5 +1,5 @@ @model CostMakeUpForVehicle - + \ No newline at end of file diff --git a/Views/Vehicle/_Report.cshtml b/Views/Vehicle/_Report.cshtml index ab6e977..c42d979 100644 --- a/Views/Vehicle/_Report.cshtml +++ b/Views/Vehicle/_Report.cshtml @@ -6,8 +6,7 @@