force a page refresh if there are oudated recurring tax records on vehicle load.
This commit is contained in:
@@ -569,6 +569,41 @@ namespace CarCareTracker.Controllers
|
|||||||
return Json(result);
|
return Json(result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
[HttpGet]
|
||||||
|
[Route("/api/vehicle/taxrecords/check")]
|
||||||
|
public IActionResult CheckRecurringTaxRecords()
|
||||||
|
{
|
||||||
|
List<Vehicle> vehicles = new List<Vehicle>();
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var result = _dataAccess.GetVehicles();
|
||||||
|
if (!User.IsInRole(nameof(UserData.IsRootUser)))
|
||||||
|
{
|
||||||
|
result = _userLogic.FilterUserVehicles(result, GetUserID());
|
||||||
|
}
|
||||||
|
vehicles.AddRange(result);
|
||||||
|
int vehiclesUpdated = 0;
|
||||||
|
foreach(Vehicle vehicle in vehicles)
|
||||||
|
{
|
||||||
|
var updateResult = _vehicleLogic.UpdateRecurringTaxes(vehicle.Id);
|
||||||
|
if (updateResult)
|
||||||
|
{
|
||||||
|
vehiclesUpdated++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (vehiclesUpdated != default)
|
||||||
|
{
|
||||||
|
return Json(OperationResponse.Succeed($"Recurring Taxes for {vehiclesUpdated} Vehicles Updated!"));
|
||||||
|
} else
|
||||||
|
{
|
||||||
|
return Json(OperationResponse.Succeed("No Recurring Taxes Updated"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
return Json(OperationResponse.Failed($"No Recurring Taxes Updated Due To Error: {ex.Message}"));
|
||||||
|
}
|
||||||
|
}
|
||||||
[TypeFilter(typeof(CollaboratorFilter))]
|
[TypeFilter(typeof(CollaboratorFilter))]
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
[Route("/api/vehicle/taxrecords/add")]
|
[Route("/api/vehicle/taxrecords/add")]
|
||||||
|
|||||||
@@ -30,8 +30,8 @@ namespace CarCareTracker.Controllers
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
_vehicleLogic.UpdateRecurringTaxes(vehicleId);
|
var result = _vehicleLogic.UpdateRecurringTaxes(vehicleId);
|
||||||
return Json(true);
|
return Json(result);
|
||||||
} catch (Exception ex)
|
} catch (Exception ex)
|
||||||
{
|
{
|
||||||
_logger.LogError(ex.Message);
|
_logger.LogError(ex.Message);
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ namespace CarCareTracker.Logic
|
|||||||
List<VehicleInfo> GetVehicleInfo(List<Vehicle> vehicles);
|
List<VehicleInfo> GetVehicleInfo(List<Vehicle> vehicles);
|
||||||
List<ReminderRecordViewModel> GetReminders(List<Vehicle> vehicles, bool isCalendar);
|
List<ReminderRecordViewModel> GetReminders(List<Vehicle> vehicles, bool isCalendar);
|
||||||
List<PlanRecord> GetPlans(List<Vehicle> vehicles, bool excludeDone);
|
List<PlanRecord> GetPlans(List<Vehicle> vehicles, bool excludeDone);
|
||||||
void UpdateRecurringTaxes(int vehicleId);
|
bool UpdateRecurringTaxes(int vehicleId);
|
||||||
}
|
}
|
||||||
public class VehicleLogic: IVehicleLogic
|
public class VehicleLogic: IVehicleLogic
|
||||||
{
|
{
|
||||||
@@ -322,12 +322,12 @@ namespace CarCareTracker.Logic
|
|||||||
}
|
}
|
||||||
return plans.OrderBy(x => x.Priority).ThenBy(x=>x.Progress).ToList();
|
return plans.OrderBy(x => x.Priority).ThenBy(x=>x.Progress).ToList();
|
||||||
}
|
}
|
||||||
public void UpdateRecurringTaxes(int vehicleId)
|
public bool UpdateRecurringTaxes(int vehicleId)
|
||||||
{
|
{
|
||||||
var vehicleData = _dataAccess.GetVehicleById(vehicleId);
|
var vehicleData = _dataAccess.GetVehicleById(vehicleId);
|
||||||
if (!string.IsNullOrWhiteSpace(vehicleData.SoldDate))
|
if (!string.IsNullOrWhiteSpace(vehicleData.SoldDate))
|
||||||
{
|
{
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
bool RecurringTaxIsOutdated(TaxRecord taxRecord)
|
bool RecurringTaxIsOutdated(TaxRecord taxRecord)
|
||||||
{
|
{
|
||||||
@@ -338,6 +338,7 @@ namespace CarCareTracker.Logic
|
|||||||
var outdatedRecurringFees = result.Where(x => x.IsRecurring && RecurringTaxIsOutdated(x));
|
var outdatedRecurringFees = result.Where(x => x.IsRecurring && RecurringTaxIsOutdated(x));
|
||||||
if (outdatedRecurringFees.Any())
|
if (outdatedRecurringFees.Any())
|
||||||
{
|
{
|
||||||
|
var success = false;
|
||||||
foreach (TaxRecord recurringFee in outdatedRecurringFees)
|
foreach (TaxRecord recurringFee in outdatedRecurringFees)
|
||||||
{
|
{
|
||||||
var monthInterval = recurringFee.RecurringInterval != ReminderMonthInterval.Other ? (int)recurringFee.RecurringInterval : recurringFee.CustomMonthInterval;
|
var monthInterval = recurringFee.RecurringInterval != ReminderMonthInterval.Other ? (int)recurringFee.RecurringInterval : recurringFee.CustomMonthInterval;
|
||||||
@@ -360,14 +361,18 @@ namespace CarCareTracker.Logic
|
|||||||
recurringFee.IsRecurring = DateTime.Now <= nextnextDate;
|
recurringFee.IsRecurring = DateTime.Now <= nextnextDate;
|
||||||
_taxRecordDataAccess.SaveTaxRecordToVehicle(recurringFee);
|
_taxRecordDataAccess.SaveTaxRecordToVehicle(recurringFee);
|
||||||
isOutdated = !recurringFee.IsRecurring;
|
isOutdated = !recurringFee.IsRecurring;
|
||||||
|
success = true;
|
||||||
}
|
}
|
||||||
catch (Exception)
|
catch (Exception)
|
||||||
{
|
{
|
||||||
isOutdated = false; //break out of loop if something broke.
|
isOutdated = false; //break out of loop if something broke.
|
||||||
|
success = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return success;
|
||||||
}
|
}
|
||||||
|
return false; //no outdated recurring tax records.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -344,6 +344,20 @@
|
|||||||
vehicleId - Id of Vehicle
|
vehicleId - Id of Vehicle
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="row api-method">
|
||||||
|
<div class="col-1">
|
||||||
|
<span class="badge bg-success">GET</span>
|
||||||
|
</div>
|
||||||
|
<div class="col-5 copyable">
|
||||||
|
<code>/api/vehicle/taxrecords/check</code>
|
||||||
|
</div>
|
||||||
|
<div class="col-3">
|
||||||
|
Updates Outdated Recurring Tax Records
|
||||||
|
</div>
|
||||||
|
<div class="col-3">
|
||||||
|
No Params
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
<div class="row api-method">
|
<div class="row api-method">
|
||||||
<div class="col-1">
|
<div class="col-1">
|
||||||
<span class="badge bg-primary">POST</span>
|
<span class="badge bg-primary">POST</span>
|
||||||
|
|||||||
@@ -181,9 +181,9 @@ function getAndValidateTaxRecordValues() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function checkRecurringTaxes() {
|
function checkRecurringTaxes() {
|
||||||
$.post('/Vehicle/CheckRecurringTaxRecords', { vehicleId: GetVehicleId().vehicleId },function (data) {
|
$.post('/Vehicle/CheckRecurringTaxRecords', { vehicleId: GetVehicleId().vehicleId }, function (data) {
|
||||||
if (!data) {
|
if (data) {
|
||||||
errorToast(genericErrorMessage());
|
viewVehicle(GetVehicleId().vehicleId);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user