added object inheritance.
This commit is contained in:
@@ -1609,5 +1609,55 @@ namespace CarCareTracker.Controllers
|
||||
return Json(result);
|
||||
}
|
||||
#endregion
|
||||
#region "Shared Methods"
|
||||
public IActionResult MoveRecord(int recordId, ImportMode source, ImportMode destination)
|
||||
{
|
||||
var genericRecord = new GenericRecord();
|
||||
bool result = false;
|
||||
//get
|
||||
switch (source)
|
||||
{
|
||||
case ImportMode.ServiceRecord:
|
||||
genericRecord = _serviceRecordDataAccess.GetServiceRecordById(recordId);
|
||||
break;
|
||||
case ImportMode.RepairRecord:
|
||||
genericRecord = _collisionRecordDataAccess.GetCollisionRecordById(recordId);
|
||||
break;
|
||||
case ImportMode.UpgradeRecord:
|
||||
genericRecord = _upgradeRecordDataAccess.GetUpgradeRecordById(recordId);
|
||||
break;
|
||||
}
|
||||
//save
|
||||
switch (destination)
|
||||
{
|
||||
case ImportMode.ServiceRecord:
|
||||
result = _serviceRecordDataAccess.SaveServiceRecordToVehicle(StaticHelper.GenericToServiceRecord(genericRecord));
|
||||
break;
|
||||
case ImportMode.RepairRecord:
|
||||
result = _collisionRecordDataAccess.SaveCollisionRecordToVehicle(StaticHelper.GenericToRepairRecord(genericRecord));
|
||||
break;
|
||||
case ImportMode.UpgradeRecord:
|
||||
result = _upgradeRecordDataAccess.SaveUpgradeRecordToVehicle(StaticHelper.GenericToUpgradeRecord(genericRecord));
|
||||
break;
|
||||
}
|
||||
//delete
|
||||
if (result)
|
||||
{
|
||||
switch (source)
|
||||
{
|
||||
case ImportMode.ServiceRecord:
|
||||
_serviceRecordDataAccess.DeleteServiceRecordById(recordId);
|
||||
break;
|
||||
case ImportMode.RepairRecord:
|
||||
_collisionRecordDataAccess.DeleteCollisionRecordById(recordId);
|
||||
break;
|
||||
case ImportMode.UpgradeRecord:
|
||||
_upgradeRecordDataAccess.DeleteUpgradeRecordById(recordId);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return Json(result);
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
@@ -100,5 +100,45 @@ namespace CarCareTracker.Helper
|
||||
new CostForVehicleByMonth { MonthId = 12, Cost = 0M}
|
||||
};
|
||||
}
|
||||
|
||||
public static ServiceRecord GenericToServiceRecord(GenericRecord input)
|
||||
{
|
||||
return new ServiceRecord
|
||||
{
|
||||
VehicleId = input.VehicleId,
|
||||
Date = input.Date,
|
||||
Description = input.Description,
|
||||
Cost = input.Cost,
|
||||
Mileage = input.Mileage,
|
||||
Files = input.Files,
|
||||
Notes = input.Notes
|
||||
};
|
||||
}
|
||||
public static CollisionRecord GenericToRepairRecord(GenericRecord input)
|
||||
{
|
||||
return new CollisionRecord
|
||||
{
|
||||
VehicleId = input.VehicleId,
|
||||
Date = input.Date,
|
||||
Description = input.Description,
|
||||
Cost = input.Cost,
|
||||
Mileage = input.Mileage,
|
||||
Files = input.Files,
|
||||
Notes = input.Notes
|
||||
};
|
||||
}
|
||||
public static UpgradeRecord GenericToUpgradeRecord(GenericRecord input)
|
||||
{
|
||||
return new UpgradeRecord
|
||||
{
|
||||
VehicleId = input.VehicleId,
|
||||
Date = input.Date,
|
||||
Description = input.Description,
|
||||
Cost = input.Cost,
|
||||
Mileage = input.Mileage,
|
||||
Files = input.Files,
|
||||
Notes = input.Notes
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,14 +1,6 @@
|
||||
namespace CarCareTracker.Models
|
||||
{
|
||||
public class CollisionRecord
|
||||
public class CollisionRecord: GenericRecord
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public int VehicleId { get; set; }
|
||||
public DateTime Date { get; set; }
|
||||
public int Mileage { get; set; }
|
||||
public string Description { get; set; }
|
||||
public decimal Cost { get; set; }
|
||||
public string Notes { get; set; }
|
||||
public List<UploadedFiles> Files { get; set; } = new List<UploadedFiles>();
|
||||
}
|
||||
}
|
||||
|
||||
14
Models/GenericRecord.cs
Normal file
14
Models/GenericRecord.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
namespace CarCareTracker.Models
|
||||
{
|
||||
public class GenericRecord
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public int VehicleId { get; set; }
|
||||
public DateTime Date { get; set; }
|
||||
public int Mileage { get; set; }
|
||||
public string Description { get; set; }
|
||||
public decimal Cost { get; set; }
|
||||
public string Notes { get; set; }
|
||||
public List<UploadedFiles> Files { get; set; } = new List<UploadedFiles>();
|
||||
}
|
||||
}
|
||||
@@ -1,14 +1,6 @@
|
||||
namespace CarCareTracker.Models
|
||||
{
|
||||
public class ServiceRecord
|
||||
public class ServiceRecord: GenericRecord
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public int VehicleId { get; set; }
|
||||
public DateTime Date { get; set; }
|
||||
public int Mileage { get; set; }
|
||||
public string Description { get; set; }
|
||||
public decimal Cost { get; set; }
|
||||
public string Notes { get; set; }
|
||||
public List<UploadedFiles> Files { get; set; } = new List<UploadedFiles>();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,14 +1,6 @@
|
||||
namespace CarCareTracker.Models
|
||||
{
|
||||
public class UpgradeRecord
|
||||
public class UpgradeRecord: GenericRecord
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public int VehicleId { get; set; }
|
||||
public DateTime Date { get; set; }
|
||||
public int Mileage { get; set; }
|
||||
public string Description { get; set; }
|
||||
public decimal Cost { get; set; }
|
||||
public string Notes { get; set; }
|
||||
public List<UploadedFiles> Files { get; set; } = new List<UploadedFiles>();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -63,7 +63,17 @@
|
||||
<div class="modal-footer">
|
||||
@if (!isNew)
|
||||
{
|
||||
<button type="button" class="btn btn-danger" onclick="deleteCollisionRecord(@Model.Id)" style="margin-right:auto;">Delete</button>
|
||||
<div class="btn-group" style="margin-right:auto;">
|
||||
<button type="button" class="btn btn-md mt-1 mb-1 btn-danger" onclick="deleteCollisionRecord(@Model.Id)">Delete</button>
|
||||
<button type="button" class="btn btn-md btn-danger btn-md mt-1 mb-1 dropdown-toggle dropdown-toggle-split" data-bs-toggle="dropdown" aria-expanded="false">
|
||||
<span class="visually-hidden">Toggle Dropdown</span>
|
||||
</button>
|
||||
<ul class="dropdown-menu">
|
||||
<li><h6 class="dropdown-header">Move To</h6></li>
|
||||
<li><a class="dropdown-item" href="#" onclick="moveRecord(@Model.Id, 'RepairRecord', 'ServiceRecord')">Service Records</a></li>
|
||||
<li><a class="dropdown-item" href="#" onclick="moveRecord(@Model.Id, 'RepairRecord', 'UpgradeRecord')">Upgrades</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
}
|
||||
<button type="button" class="btn btn-secondary" onclick="hideAddCollisionRecordModal()">Cancel</button>
|
||||
@if (isNew)
|
||||
|
||||
@@ -63,7 +63,17 @@
|
||||
<div class="modal-footer">
|
||||
@if (!isNew)
|
||||
{
|
||||
<button type="button" class="btn btn-danger" onclick="deleteServiceRecord(@Model.Id)" style="margin-right:auto;">Delete</button>
|
||||
<div class="btn-group" style="margin-right:auto;">
|
||||
<button type="button" class="btn btn-md mt-1 mb-1 btn-danger" onclick="deleteServiceRecord(@Model.Id)" >Delete</button>
|
||||
<button type="button" class="btn btn-md btn-danger btn-md mt-1 mb-1 dropdown-toggle dropdown-toggle-split" data-bs-toggle="dropdown" aria-expanded="false">
|
||||
<span class="visually-hidden">Toggle Dropdown</span>
|
||||
</button>
|
||||
<ul class="dropdown-menu">
|
||||
<li><h6 class="dropdown-header">Move To</h6></li>
|
||||
<li><a class="dropdown-item" href="#" onclick="moveRecord(@Model.Id, 'ServiceRecord', 'RepairRecord')">Repairs</a></li>
|
||||
<li><a class="dropdown-item" href="#" onclick="moveRecord(@Model.Id, 'ServiceRecord', 'UpgradeRecord')">Upgrades</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
}
|
||||
<button type="button" class="btn btn-secondary" onclick="hideAddServiceRecordModal()">Cancel</button>
|
||||
@if (isNew)
|
||||
|
||||
@@ -63,7 +63,17 @@
|
||||
<div class="modal-footer">
|
||||
@if (!isNew)
|
||||
{
|
||||
<button type="button" class="btn btn-danger" onclick="deleteUpgradeRecord(@Model.Id)" style="margin-right:auto;">Delete</button>
|
||||
<div class="btn-group" style="margin-right:auto;">
|
||||
<button type="button" class="btn btn-md mt-1 mb-1 btn-danger" onclick="deleteUpgradeRecord(@Model.Id)">Delete</button>
|
||||
<button type="button" class="btn btn-md btn-danger btn-md mt-1 mb-1 dropdown-toggle dropdown-toggle-split" data-bs-toggle="dropdown" aria-expanded="false">
|
||||
<span class="visually-hidden">Toggle Dropdown</span>
|
||||
</button>
|
||||
<ul class="dropdown-menu">
|
||||
<li><h6 class="dropdown-header">Move To</h6></li>
|
||||
<li><a class="dropdown-item" href="#" onclick="moveRecord(@Model.Id, 'UpgradeRecord', 'ServiceRecord')">Service Records</a></li>
|
||||
<li><a class="dropdown-item" href="#" onclick="moveRecord(@Model.Id, 'UpgradeRecord', 'RepairRecord')">Repairs</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
}
|
||||
<button type="button" class="btn btn-secondary" onclick="hideAddUpgradeRecordModal()">Cancel</button>
|
||||
@if (isNew)
|
||||
|
||||
@@ -353,4 +353,61 @@ function saveScrollPosition() {
|
||||
function restoreScrollPosition() {
|
||||
$(".vehicleDetailTabContainer").scrollTop(scrollPosition);
|
||||
scrollPosition = 0;
|
||||
}
|
||||
function moveRecord(recordId, source, dest) {
|
||||
$("#workAroundInput").show();
|
||||
var friendlySource = "";
|
||||
var friendlyDest = "";
|
||||
var hideModalCallBack;
|
||||
var refreshDataCallBack;
|
||||
switch (source) {
|
||||
case "ServiceRecord":
|
||||
friendlySource = "Service Records";
|
||||
hideModalCallBack = hideAddServiceRecordModal;
|
||||
refreshDataCallBack = getVehicleServiceRecords;
|
||||
break;
|
||||
case "RepairRecord":
|
||||
friendlySource = "Repairs";
|
||||
hideModalCallBack = hideAddCollisionRecordModal;
|
||||
refreshDataCallBack = getVehicleCollisionRecords;
|
||||
break;
|
||||
case "UpgradeRecord":
|
||||
friendlySource = "Upgrades";
|
||||
hideModalCallBack = hideAddUpgradeRecordModal;
|
||||
refreshDataCallBack = getVehicleUpgradeRecords;
|
||||
break;
|
||||
}
|
||||
switch (dest) {
|
||||
case "ServiceRecord":
|
||||
friendlyDest = "Service Records";
|
||||
break;
|
||||
case "RepairRecord":
|
||||
friendlyDest = "Repairs";
|
||||
break;
|
||||
case "UpgradeRecord":
|
||||
friendlyDest = "Upgrades";
|
||||
break;
|
||||
}
|
||||
Swal.fire({
|
||||
title: "Confirm Move?",
|
||||
text: `Move this record from ${friendlySource} to ${friendlyDest}?`,
|
||||
showCancelButton: true,
|
||||
confirmButtonText: "Move",
|
||||
confirmButtonColor: "#dc3545"
|
||||
}).then((result) => {
|
||||
if (result.isConfirmed) {
|
||||
$.post('/Vehicle/MoveRecord', {recordId: recordId, source: source, destination: dest }, function (data) {
|
||||
if (data) {
|
||||
hideModalCallBack();
|
||||
successToast("Record Moved");
|
||||
var vehicleId = GetVehicleId().vehicleId;
|
||||
refreshDataCallBack(vehicleId);
|
||||
} else {
|
||||
errorToast("An error has occurred, please try again later.");
|
||||
}
|
||||
});
|
||||
} else {
|
||||
$("#workAroundInput").hide();
|
||||
}
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user