Merge pull request #222 from hargata/Hargata/tags.export

added tags export to csv.
This commit is contained in:
Hargata Softworks 2024-02-03 06:13:06 -07:00 committed by GitHub
commit 351db5de95
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 37 additions and 18 deletions

View File

@ -172,7 +172,7 @@ namespace CarCareTracker.Controllers
var vehicleRecords = _serviceRecordDataAccess.GetServiceRecordsByVehicleId(vehicleId); var vehicleRecords = _serviceRecordDataAccess.GetServiceRecordsByVehicleId(vehicleId);
if (vehicleRecords.Any()) if (vehicleRecords.Any())
{ {
var exportData = vehicleRecords.Select(x => new ServiceRecordExportModel { Date = x.Date.ToShortDateString(), Description = x.Description, Cost = x.Cost.ToString("C"), Notes = x.Notes, Odometer = x.Mileage.ToString() }); var exportData = vehicleRecords.Select(x => new ServiceRecordExportModel { Date = x.Date.ToShortDateString(), Description = x.Description, Cost = x.Cost.ToString("C"), Notes = x.Notes, Odometer = x.Mileage.ToString(), Tags = string.Join(" ", x.Tags) });
using (var writer = new StreamWriter(fullExportFilePath)) using (var writer = new StreamWriter(fullExportFilePath))
{ {
using (var csv = new CsvWriter(writer, CultureInfo.InvariantCulture)) using (var csv = new CsvWriter(writer, CultureInfo.InvariantCulture))
@ -190,7 +190,7 @@ namespace CarCareTracker.Controllers
var vehicleRecords = _collisionRecordDataAccess.GetCollisionRecordsByVehicleId(vehicleId); var vehicleRecords = _collisionRecordDataAccess.GetCollisionRecordsByVehicleId(vehicleId);
if (vehicleRecords.Any()) if (vehicleRecords.Any())
{ {
var exportData = vehicleRecords.Select(x => new ServiceRecordExportModel { Date = x.Date.ToShortDateString(), Description = x.Description, Cost = x.Cost.ToString("C"), Notes = x.Notes, Odometer = x.Mileage.ToString() }); var exportData = vehicleRecords.Select(x => new ServiceRecordExportModel { Date = x.Date.ToShortDateString(), Description = x.Description, Cost = x.Cost.ToString("C"), Notes = x.Notes, Odometer = x.Mileage.ToString(), Tags = string.Join(" ", x.Tags) });
using (var writer = new StreamWriter(fullExportFilePath)) using (var writer = new StreamWriter(fullExportFilePath))
{ {
using (var csv = new CsvWriter(writer, CultureInfo.InvariantCulture)) using (var csv = new CsvWriter(writer, CultureInfo.InvariantCulture))
@ -208,7 +208,7 @@ namespace CarCareTracker.Controllers
var vehicleRecords = _upgradeRecordDataAccess.GetUpgradeRecordsByVehicleId(vehicleId); var vehicleRecords = _upgradeRecordDataAccess.GetUpgradeRecordsByVehicleId(vehicleId);
if (vehicleRecords.Any()) if (vehicleRecords.Any())
{ {
var exportData = vehicleRecords.Select(x => new ServiceRecordExportModel { Date = x.Date.ToShortDateString(), Description = x.Description, Cost = x.Cost.ToString("C"), Notes = x.Notes, Odometer = x.Mileage.ToString() }); var exportData = vehicleRecords.Select(x => new ServiceRecordExportModel { Date = x.Date.ToShortDateString(), Description = x.Description, Cost = x.Cost.ToString("C"), Notes = x.Notes, Odometer = x.Mileage.ToString(), Tags = string.Join(" ", x.Tags) });
using (var writer = new StreamWriter(fullExportFilePath)) using (var writer = new StreamWriter(fullExportFilePath))
{ {
using (var csv = new CsvWriter(writer, CultureInfo.InvariantCulture)) using (var csv = new CsvWriter(writer, CultureInfo.InvariantCulture))
@ -226,7 +226,7 @@ namespace CarCareTracker.Controllers
var vehicleRecords = _odometerRecordDataAccess.GetOdometerRecordsByVehicleId(vehicleId); var vehicleRecords = _odometerRecordDataAccess.GetOdometerRecordsByVehicleId(vehicleId);
if (vehicleRecords.Any()) if (vehicleRecords.Any())
{ {
var exportData = vehicleRecords.Select(x => new OdometerRecordExportModel { Date = x.Date.ToShortDateString(), Notes = x.Notes, Odometer = x.Mileage.ToString() }); var exportData = vehicleRecords.Select(x => new OdometerRecordExportModel { Date = x.Date.ToShortDateString(), Notes = x.Notes, Odometer = x.Mileage.ToString(), Tags = string.Join(" ", x.Tags) });
using (var writer = new StreamWriter(fullExportFilePath)) using (var writer = new StreamWriter(fullExportFilePath))
{ {
using (var csv = new CsvWriter(writer, CultureInfo.InvariantCulture)) using (var csv = new CsvWriter(writer, CultureInfo.InvariantCulture))
@ -271,7 +271,7 @@ namespace CarCareTracker.Controllers
var vehicleRecords = _taxRecordDataAccess.GetTaxRecordsByVehicleId(vehicleId); var vehicleRecords = _taxRecordDataAccess.GetTaxRecordsByVehicleId(vehicleId);
if (vehicleRecords.Any()) if (vehicleRecords.Any())
{ {
var exportData = vehicleRecords.Select(x => new TaxRecordExportModel { Date = x.Date.ToShortDateString(), Description = x.Description, Cost = x.Cost.ToString("C"), Notes = x.Notes }); var exportData = vehicleRecords.Select(x => new TaxRecordExportModel { Date = x.Date.ToShortDateString(), Description = x.Description, Cost = x.Cost.ToString("C"), Notes = x.Notes, Tags = string.Join(" ", x.Tags) });
using (var writer = new StreamWriter(fullExportFilePath)) using (var writer = new StreamWriter(fullExportFilePath))
{ {
using (var csv = new CsvWriter(writer, CultureInfo.InvariantCulture)) using (var csv = new CsvWriter(writer, CultureInfo.InvariantCulture))
@ -327,7 +327,8 @@ namespace CarCareTracker.Controllers
Odometer = x.Mileage.ToString(), Odometer = x.Mileage.ToString(),
IsFillToFull = x.IsFillToFull.ToString(), IsFillToFull = x.IsFillToFull.ToString(),
MissedFuelUp = x.MissedFuelUp.ToString(), MissedFuelUp = x.MissedFuelUp.ToString(),
Notes = x.Notes Notes = x.Notes,
Tags = string.Join(" ", x.Tags)
}); });
using (var writer = new StreamWriter(fullExportFilePath)) using (var writer = new StreamWriter(fullExportFilePath))
{ {
@ -378,7 +379,8 @@ namespace CarCareTracker.Controllers
Date = DateTime.Parse(importModel.Date), Date = DateTime.Parse(importModel.Date),
Mileage = decimal.ToInt32(decimal.Parse(importModel.Odometer, NumberStyles.Any)), Mileage = decimal.ToInt32(decimal.Parse(importModel.Odometer, NumberStyles.Any)),
Gallons = decimal.Parse(importModel.FuelConsumed, NumberStyles.Any), Gallons = decimal.Parse(importModel.FuelConsumed, NumberStyles.Any),
Notes = string.IsNullOrWhiteSpace(importModel.Notes) ? "" : importModel.Notes Notes = string.IsNullOrWhiteSpace(importModel.Notes) ? "" : importModel.Notes,
Tags = string.IsNullOrWhiteSpace(importModel.Tags) ? [] : importModel.Tags.Split(" ").ToList()
}; };
if (string.IsNullOrWhiteSpace(importModel.Cost) && !string.IsNullOrWhiteSpace(importModel.Price)) if (string.IsNullOrWhiteSpace(importModel.Cost) && !string.IsNullOrWhiteSpace(importModel.Price))
{ {
@ -423,7 +425,8 @@ namespace CarCareTracker.Controllers
Mileage = decimal.ToInt32(decimal.Parse(importModel.Odometer, NumberStyles.Any)), Mileage = decimal.ToInt32(decimal.Parse(importModel.Odometer, NumberStyles.Any)),
Description = string.IsNullOrWhiteSpace(importModel.Description) ? $"Service Record on {importModel.Date}" : importModel.Description, Description = string.IsNullOrWhiteSpace(importModel.Description) ? $"Service Record on {importModel.Date}" : importModel.Description,
Notes = string.IsNullOrWhiteSpace(importModel.Notes) ? "" : importModel.Notes, Notes = string.IsNullOrWhiteSpace(importModel.Notes) ? "" : importModel.Notes,
Cost = decimal.Parse(importModel.Cost, NumberStyles.Any) Cost = decimal.Parse(importModel.Cost, NumberStyles.Any),
Tags = string.IsNullOrWhiteSpace(importModel.Tags) ? [] : importModel.Tags.Split(" ").ToList()
}; };
_serviceRecordDataAccess.SaveServiceRecordToVehicle(convertedRecord); _serviceRecordDataAccess.SaveServiceRecordToVehicle(convertedRecord);
} }
@ -434,7 +437,8 @@ namespace CarCareTracker.Controllers
VehicleId = vehicleId, VehicleId = vehicleId,
Date = DateTime.Parse(importModel.Date), Date = DateTime.Parse(importModel.Date),
Mileage = decimal.ToInt32(decimal.Parse(importModel.Odometer, NumberStyles.Any)), Mileage = decimal.ToInt32(decimal.Parse(importModel.Odometer, NumberStyles.Any)),
Notes = string.IsNullOrWhiteSpace(importModel.Notes) ? "" : importModel.Notes Notes = string.IsNullOrWhiteSpace(importModel.Notes) ? "" : importModel.Notes,
Tags = string.IsNullOrWhiteSpace(importModel.Tags) ? [] : importModel.Tags.Split(" ").ToList()
}; };
_odometerRecordDataAccess.SaveOdometerRecordToVehicle(convertedRecord); _odometerRecordDataAccess.SaveOdometerRecordToVehicle(convertedRecord);
} }
@ -466,7 +470,8 @@ namespace CarCareTracker.Controllers
Mileage = decimal.ToInt32(decimal.Parse(importModel.Odometer, NumberStyles.Any)), Mileage = decimal.ToInt32(decimal.Parse(importModel.Odometer, NumberStyles.Any)),
Description = string.IsNullOrWhiteSpace(importModel.Description) ? $"Repair Record on {importModel.Date}" : importModel.Description, Description = string.IsNullOrWhiteSpace(importModel.Description) ? $"Repair Record on {importModel.Date}" : importModel.Description,
Notes = string.IsNullOrWhiteSpace(importModel.Notes) ? "" : importModel.Notes, Notes = string.IsNullOrWhiteSpace(importModel.Notes) ? "" : importModel.Notes,
Cost = decimal.Parse(importModel.Cost, NumberStyles.Any) Cost = decimal.Parse(importModel.Cost, NumberStyles.Any),
Tags = string.IsNullOrWhiteSpace(importModel.Tags) ? [] : importModel.Tags.Split(" ").ToList()
}; };
_collisionRecordDataAccess.SaveCollisionRecordToVehicle(convertedRecord); _collisionRecordDataAccess.SaveCollisionRecordToVehicle(convertedRecord);
} }
@ -479,7 +484,8 @@ namespace CarCareTracker.Controllers
Mileage = decimal.ToInt32(decimal.Parse(importModel.Odometer, NumberStyles.Any)), Mileage = decimal.ToInt32(decimal.Parse(importModel.Odometer, NumberStyles.Any)),
Description = string.IsNullOrWhiteSpace(importModel.Description) ? $"Upgrade Record on {importModel.Date}" : importModel.Description, Description = string.IsNullOrWhiteSpace(importModel.Description) ? $"Upgrade Record on {importModel.Date}" : importModel.Description,
Notes = string.IsNullOrWhiteSpace(importModel.Notes) ? "" : importModel.Notes, Notes = string.IsNullOrWhiteSpace(importModel.Notes) ? "" : importModel.Notes,
Cost = decimal.Parse(importModel.Cost, NumberStyles.Any) Cost = decimal.Parse(importModel.Cost, NumberStyles.Any),
Tags = string.IsNullOrWhiteSpace(importModel.Tags) ? [] : importModel.Tags.Split(" ").ToList()
}; };
_upgradeRecordDataAccess.SaveUpgradeRecordToVehicle(convertedRecord); _upgradeRecordDataAccess.SaveUpgradeRecordToVehicle(convertedRecord);
} }
@ -506,7 +512,8 @@ namespace CarCareTracker.Controllers
Date = DateTime.Parse(importModel.Date), Date = DateTime.Parse(importModel.Date),
Description = string.IsNullOrWhiteSpace(importModel.Description) ? $"Tax Record on {importModel.Date}" : importModel.Description, Description = string.IsNullOrWhiteSpace(importModel.Description) ? $"Tax Record on {importModel.Date}" : importModel.Description,
Notes = string.IsNullOrWhiteSpace(importModel.Notes) ? "" : importModel.Notes, Notes = string.IsNullOrWhiteSpace(importModel.Notes) ? "" : importModel.Notes,
Cost = decimal.Parse(importModel.Cost, NumberStyles.Any) Cost = decimal.Parse(importModel.Cost, NumberStyles.Any),
Tags = string.IsNullOrWhiteSpace(importModel.Tags) ? [] : importModel.Tags.Split(" ").ToList()
}; };
_taxRecordDataAccess.SaveTaxRecordToVehicle(convertedRecord); _taxRecordDataAccess.SaveTaxRecordToVehicle(convertedRecord);
} }

View File

@ -14,14 +14,20 @@ namespace CarCareTracker.Helper
var recordsToCalculate = results.Where(x => x.IncludeInAverage); var recordsToCalculate = results.Where(x => x.IncludeInAverage);
if (recordsToCalculate.Any()) if (recordsToCalculate.Any())
{ {
var totalMileage = recordsToCalculate.Sum(x => x.DeltaMileage); try
var totalGallons = recordsToCalculate.Sum(x => x.Gallons);
var averageGasMileage = totalMileage / totalGallons;
if (!useMPG)
{ {
averageGasMileage = 100 / averageGasMileage; var totalMileage = recordsToCalculate.Sum(x => x.DeltaMileage);
var totalGallons = recordsToCalculate.Sum(x => x.Gallons);
var averageGasMileage = totalMileage / totalGallons;
if (!useMPG && averageGasMileage > 0)
{
averageGasMileage = 100 / averageGasMileage;
}
return averageGasMileage.ToString("F");
} catch (Exception ex)
{
return "0";
} }
return averageGasMileage.ToString("F");
} }
return "0"; return "0";
} }

View File

@ -25,6 +25,7 @@ namespace CarCareTracker.MapProfile
Map(m => m.Progress).Name(["progress"]); Map(m => m.Progress).Name(["progress"]);
Map(m => m.Type).Name(["type"]); Map(m => m.Type).Name(["type"]);
Map(m => m.Priority).Name(["priority"]); Map(m => m.Priority).Name(["priority"]);
Map(m => m.Tags).Name(["tags"]);
} }
} }
} }

View File

@ -23,6 +23,7 @@
public string PartNumber { get; set; } public string PartNumber { get; set; }
public string PartSupplier { get; set; } public string PartSupplier { get; set; }
public string PartQuantity { get; set; } public string PartQuantity { get; set; }
public string Tags { get; set; }
} }
public class SupplyRecordExportModel public class SupplyRecordExportModel
@ -43,12 +44,14 @@
public string Description { get; set; } public string Description { get; set; }
public string Notes { get; set; } public string Notes { get; set; }
public string Cost { get; set; } public string Cost { get; set; }
public string Tags { get; set; }
} }
public class OdometerRecordExportModel public class OdometerRecordExportModel
{ {
public string Date { get; set; } public string Date { get; set; }
public string Odometer { get; set; } public string Odometer { get; set; }
public string Notes { get; set; } public string Notes { get; set; }
public string Tags { get; set; }
} }
public class TaxRecordExportModel public class TaxRecordExportModel
{ {
@ -56,6 +59,7 @@
public string Description { get; set; } public string Description { get; set; }
public string Notes { get; set; } public string Notes { get; set; }
public string Cost { get; set; } public string Cost { get; set; }
public string Tags { get; set; }
} }
public class GasRecordExportModel public class GasRecordExportModel
{ {
@ -67,6 +71,7 @@
public string IsFillToFull { get; set; } public string IsFillToFull { get; set; }
public string MissedFuelUp { get; set; } public string MissedFuelUp { get; set; }
public string Notes { get; set; } public string Notes { get; set; }
public string Tags { get; set; }
} }
public class ReminderExportModel public class ReminderExportModel
{ {