inject reminderrecord data access into vehiclecontroller.
This commit is contained in:
@@ -6,6 +6,7 @@ using CarCareTracker.Helper;
|
|||||||
using CsvHelper;
|
using CsvHelper;
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using Microsoft.AspNetCore.Authorization;
|
using Microsoft.AspNetCore.Authorization;
|
||||||
|
using CarCareTracker.External.Implementations;
|
||||||
|
|
||||||
namespace CarCareTracker.Controllers
|
namespace CarCareTracker.Controllers
|
||||||
{
|
{
|
||||||
@@ -19,6 +20,7 @@ namespace CarCareTracker.Controllers
|
|||||||
private readonly IGasRecordDataAccess _gasRecordDataAccess;
|
private readonly IGasRecordDataAccess _gasRecordDataAccess;
|
||||||
private readonly ICollisionRecordDataAccess _collisionRecordDataAccess;
|
private readonly ICollisionRecordDataAccess _collisionRecordDataAccess;
|
||||||
private readonly ITaxRecordDataAccess _taxRecordDataAccess;
|
private readonly ITaxRecordDataAccess _taxRecordDataAccess;
|
||||||
|
private readonly IReminderRecordDataAccess _reminderRecordDataAccess;
|
||||||
private readonly IWebHostEnvironment _webEnv;
|
private readonly IWebHostEnvironment _webEnv;
|
||||||
private readonly bool _useDescending;
|
private readonly bool _useDescending;
|
||||||
private readonly IConfiguration _config;
|
private readonly IConfiguration _config;
|
||||||
@@ -32,6 +34,7 @@ namespace CarCareTracker.Controllers
|
|||||||
IGasRecordDataAccess gasRecordDataAccess,
|
IGasRecordDataAccess gasRecordDataAccess,
|
||||||
ICollisionRecordDataAccess collisionRecordDataAccess,
|
ICollisionRecordDataAccess collisionRecordDataAccess,
|
||||||
ITaxRecordDataAccess taxRecordDataAccess,
|
ITaxRecordDataAccess taxRecordDataAccess,
|
||||||
|
IReminderRecordDataAccess reminderRecordDataAccess,
|
||||||
IWebHostEnvironment webEnv,
|
IWebHostEnvironment webEnv,
|
||||||
IConfiguration config)
|
IConfiguration config)
|
||||||
{
|
{
|
||||||
@@ -43,6 +46,7 @@ namespace CarCareTracker.Controllers
|
|||||||
_gasRecordDataAccess = gasRecordDataAccess;
|
_gasRecordDataAccess = gasRecordDataAccess;
|
||||||
_collisionRecordDataAccess = collisionRecordDataAccess;
|
_collisionRecordDataAccess = collisionRecordDataAccess;
|
||||||
_taxRecordDataAccess = taxRecordDataAccess;
|
_taxRecordDataAccess = taxRecordDataAccess;
|
||||||
|
_reminderRecordDataAccess = reminderRecordDataAccess;
|
||||||
_webEnv = webEnv;
|
_webEnv = webEnv;
|
||||||
_config = config;
|
_config = config;
|
||||||
_useDescending = bool.Parse(config[nameof(UserConfig.UseDescending)]);
|
_useDescending = bool.Parse(config[nameof(UserConfig.UseDescending)]);
|
||||||
@@ -538,5 +542,54 @@ namespace CarCareTracker.Controllers
|
|||||||
return PartialView("_GasCostByMonthReport", groupedGasRecord);
|
return PartialView("_GasCostByMonthReport", groupedGasRecord);
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
#region "Reminders"
|
||||||
|
[HttpGet]
|
||||||
|
public IActionResult GetReminderRecordsByVehicleId(int vehicleId)
|
||||||
|
{
|
||||||
|
var result = _reminderRecordDataAccess.GetReminderRecordsByVehicleId(vehicleId);
|
||||||
|
if (_useDescending)
|
||||||
|
{
|
||||||
|
result = result.OrderByDescending(x => x.Date).ToList();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
result = result.OrderBy(x => x.Date).ToList();
|
||||||
|
}
|
||||||
|
return PartialView("_ReminderRecords", result);
|
||||||
|
}
|
||||||
|
[HttpPost]
|
||||||
|
public IActionResult SaveReminderRecordToVehicleId(ReminderRecordInput reminderRecord)
|
||||||
|
{
|
||||||
|
var result = _reminderRecordDataAccess.SaveReminderRecordToVehicle(reminderRecord.ToReminderRecord());
|
||||||
|
return Json(result);
|
||||||
|
}
|
||||||
|
[HttpGet]
|
||||||
|
public IActionResult GetAddReminderRecordPartialView()
|
||||||
|
{
|
||||||
|
return PartialView("_ReminderRecordModal", new ReminderRecordInput());
|
||||||
|
}
|
||||||
|
[HttpGet]
|
||||||
|
public IActionResult GetReminderRecordForEditById(int reminderRecordId)
|
||||||
|
{
|
||||||
|
var result = _reminderRecordDataAccess.GetReminderRecordById(reminderRecordId);
|
||||||
|
//convert to Input object.
|
||||||
|
var convertedResult = new ReminderRecordInput
|
||||||
|
{
|
||||||
|
Id = result.Id,
|
||||||
|
Cost = result.Cost,
|
||||||
|
Date = result.Date.ToShortDateString(),
|
||||||
|
Description = result.Description,
|
||||||
|
Notes = result.Notes,
|
||||||
|
VehicleId = result.VehicleId
|
||||||
|
};
|
||||||
|
return PartialView("_ReminderRecordModal", convertedResult);
|
||||||
|
}
|
||||||
|
[HttpPost]
|
||||||
|
public IActionResult DeleteReminderRecordById(int reminderRecordId)
|
||||||
|
{
|
||||||
|
var result = _reminderRecordDataAccess.DeleteReminderRecordById(reminderRecordId);
|
||||||
|
return Json(result);
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,6 +9,5 @@
|
|||||||
public string Description { get; set; }
|
public string Description { get; set; }
|
||||||
public decimal Cost { get; set; }
|
public decimal Cost { get; set; }
|
||||||
public string Notes { get; set; }
|
public string Notes { get; set; }
|
||||||
public List<UploadedFiles> Files { get; set; } = new List<UploadedFiles>();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,7 +9,6 @@
|
|||||||
public string Description { get; set; }
|
public string Description { get; set; }
|
||||||
public decimal Cost { get; set; }
|
public decimal Cost { get; set; }
|
||||||
public string Notes { get; set; }
|
public string Notes { get; set; }
|
||||||
public List<UploadedFiles> Files { get; set; } = new List<UploadedFiles>();
|
public ReminderRecord ToReminderRecord() { return new ReminderRecord { Id = Id, VehicleId = VehicleId, Date = DateTime.Parse(Date), Cost = Cost, Mileage = Mileage, Description = Description, Notes = Notes }; }
|
||||||
public ReminderRecord ToCollisionRecord() { return new ReminderRecord { Id = Id, VehicleId = VehicleId, Date = DateTime.Parse(Date), Cost = Cost, Mileage = Mileage, Description = Description, Notes = Notes, Files = Files }; }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user