diff --git a/Controllers/Vehicle/ImportController.cs b/Controllers/Vehicle/ImportController.cs index 8f8b4ac..2f9cc1e 100644 --- a/Controllers/Vehicle/ImportController.cs +++ b/Controllers/Vehicle/ImportController.cs @@ -273,13 +273,22 @@ namespace CarCareTracker.Controllers var requiredExtraFields = _extraFieldDataAccess.GetExtraFieldsById((int)mode).ExtraFields.Where(x => x.IsRequired).Select(y => y.Name); foreach (ImportModel importModel in records) { + var parsedDate = DateTime.Now.Date; + if (!string.IsNullOrWhiteSpace(importModel.Date)) + { + parsedDate = DateTime.Parse(importModel.Date); + } + else if (!string.IsNullOrWhiteSpace(importModel.Day) && !string.IsNullOrWhiteSpace(importModel.Month) && !string.IsNullOrWhiteSpace(importModel.Year)) + { + parsedDate = new DateTime(int.Parse(importModel.Year), int.Parse(importModel.Month), int.Parse(importModel.Day)); + } if (mode == ImportMode.GasRecord) { //convert to gas model. var convertedRecord = new GasRecord() { VehicleId = vehicleId, - Date = DateTime.Parse(importModel.Date), + Date = parsedDate, Mileage = decimal.ToInt32(decimal.Parse(importModel.Odometer, NumberStyles.Any)), Gallons = decimal.Parse(importModel.FuelConsumed, NumberStyles.Any), Notes = string.IsNullOrWhiteSpace(importModel.Notes) ? "" : importModel.Notes, @@ -335,9 +344,9 @@ namespace CarCareTracker.Controllers var convertedRecord = new ServiceRecord() { VehicleId = vehicleId, - Date = DateTime.Parse(importModel.Date), + Date = parsedDate, 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 {parsedDate.ToShortDateString()}" : importModel.Description, Notes = string.IsNullOrWhiteSpace(importModel.Notes) ? "" : importModel.Notes, Cost = decimal.Parse(importModel.Cost, NumberStyles.Any), Tags = string.IsNullOrWhiteSpace(importModel.Tags) ? [] : importModel.Tags.Split(" ").ToList(), @@ -360,7 +369,7 @@ namespace CarCareTracker.Controllers var convertedRecord = new OdometerRecord() { VehicleId = vehicleId, - Date = DateTime.Parse(importModel.Date), + Date = parsedDate, InitialMileage = string.IsNullOrWhiteSpace(importModel.InitialOdometer) ? 0 : decimal.ToInt32(decimal.Parse(importModel.InitialOdometer, NumberStyles.Any)), Mileage = decimal.ToInt32(decimal.Parse(importModel.Odometer, NumberStyles.Any)), Notes = string.IsNullOrWhiteSpace(importModel.Notes) ? "" : importModel.Notes, @@ -394,9 +403,9 @@ namespace CarCareTracker.Controllers var convertedRecord = new CollisionRecord() { VehicleId = vehicleId, - Date = DateTime.Parse(importModel.Date), + Date = parsedDate, 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 {parsedDate.ToShortDateString()}" : importModel.Description, Notes = string.IsNullOrWhiteSpace(importModel.Notes) ? "" : importModel.Notes, Cost = decimal.Parse(importModel.Cost, NumberStyles.Any), Tags = string.IsNullOrWhiteSpace(importModel.Tags) ? [] : importModel.Tags.Split(" ").ToList(), @@ -419,9 +428,9 @@ namespace CarCareTracker.Controllers var convertedRecord = new UpgradeRecord() { VehicleId = vehicleId, - Date = DateTime.Parse(importModel.Date), + Date = parsedDate, 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 {parsedDate.ToShortDateString()}" : importModel.Description, Notes = string.IsNullOrWhiteSpace(importModel.Notes) ? "" : importModel.Notes, Cost = decimal.Parse(importModel.Cost, NumberStyles.Any), Tags = string.IsNullOrWhiteSpace(importModel.Tags) ? [] : importModel.Tags.Split(" ").ToList(), @@ -444,7 +453,7 @@ namespace CarCareTracker.Controllers var convertedRecord = new SupplyRecord() { VehicleId = vehicleId, - Date = DateTime.Parse(importModel.Date), + Date = parsedDate, PartNumber = importModel.PartNumber, PartSupplier = importModel.PartSupplier, Quantity = decimal.Parse(importModel.PartQuantity, NumberStyles.Any), @@ -461,8 +470,8 @@ namespace CarCareTracker.Controllers var convertedRecord = new TaxRecord() { VehicleId = vehicleId, - Date = DateTime.Parse(importModel.Date), - Description = string.IsNullOrWhiteSpace(importModel.Description) ? $"Tax Record on {importModel.Date}" : importModel.Description, + Date = parsedDate, + Description = string.IsNullOrWhiteSpace(importModel.Description) ? $"Tax Record on {parsedDate.ToShortDateString()}" : importModel.Description, Notes = string.IsNullOrWhiteSpace(importModel.Notes) ? "" : importModel.Notes, Cost = decimal.Parse(importModel.Cost, NumberStyles.Any), Tags = string.IsNullOrWhiteSpace(importModel.Tags) ? [] : importModel.Tags.Split(" ").ToList(), diff --git a/MapProfile/ImportMappers.cs b/MapProfile/ImportMappers.cs index bc23959..ead0878 100644 --- a/MapProfile/ImportMappers.cs +++ b/MapProfile/ImportMappers.cs @@ -8,18 +8,21 @@ namespace CarCareTracker.MapProfile public ImportMapper() { Map(m => m.Date).Name(["date", "fuelup_date"]); + Map(m => m.Day).Name(["day"]); + Map(m => m.Month).Name(["month"]); + Map(m => m.Year).Name(["year"]); Map(m => m.DateCreated).Name(["datecreated"]); Map(m => m.DateModified).Name(["datemodified"]); Map(m => m.InitialOdometer).Name(["initialodometer"]); Map(m => m.Odometer).Name(["odometer"]); - Map(m => m.FuelConsumed).Name(["gallons", "liters", "litres", "consumption", "quantity", "fuelconsumed"]); + Map(m => m.FuelConsumed).Name(["gallons", "liters", "litres", "consumption", "quantity", "fuelconsumed", "qty"]); Map(m => m.Cost).Name(["cost", "total cost", "totalcost", "total price"]); Map(m => m.Notes).Name("notes", "note"); Map(m => m.Price).Name(["price"]); - Map(m => m.PartialFuelUp).Name(["partial_fuelup"]); + Map(m => m.PartialFuelUp).Name(["partial_fuelup", "partial tank"]); Map(m => m.IsFillToFull).Name(["isfilltofull", "filled up"]); Map(m => m.Description).Name(["description"]); - Map(m => m.MissedFuelUp).Name(["missed_fuelup", "missedfuelup"]); + Map(m => m.MissedFuelUp).Name(["missed_fuelup", "missedfuelup", "missed fill up"]); Map(m => m.PartSupplier).Name(["partsupplier"]); Map(m => m.PartQuantity).Name(["partquantity"]); Map(m => m.PartNumber).Name(["partnumber"]); diff --git a/Models/Shared/ImportModel.cs b/Models/Shared/ImportModel.cs index 4124713..bcfcb3f 100644 --- a/Models/Shared/ImportModel.cs +++ b/Models/Shared/ImportModel.cs @@ -6,6 +6,9 @@ public class ImportModel { public string Date { get; set; } + public string Day { get; set; } + public string Month { get; set; } + public string Year { get; set; } public string DateCreated { get; set; } public string DateModified { get; set; } public string Type { get; set; }