From 2eb9a58aa6c8a9fc5ffa00c567aaec1e8a5e8a7a Mon Sep 17 00:00:00 2001 From: "DESKTOP-GENO133\\IvanPlex" Date: Fri, 19 Jan 2024 10:27:17 -0700 Subject: [PATCH 01/11] added enums. --- Enum/PlanPriority.cs | 9 +++++++++ Enum/PlanProgress.cs | 10 ++++++++++ 2 files changed, 19 insertions(+) create mode 100644 Enum/PlanPriority.cs create mode 100644 Enum/PlanProgress.cs diff --git a/Enum/PlanPriority.cs b/Enum/PlanPriority.cs new file mode 100644 index 0000000..d061835 --- /dev/null +++ b/Enum/PlanPriority.cs @@ -0,0 +1,9 @@ +namespace CarCareTracker.Enum +{ + public enum PlanPriority + { + Critical = 0, + Normal = 1, + Low = 2 + } +} diff --git a/Enum/PlanProgress.cs b/Enum/PlanProgress.cs new file mode 100644 index 0000000..f252087 --- /dev/null +++ b/Enum/PlanProgress.cs @@ -0,0 +1,10 @@ +namespace CarCareTracker.Enum +{ + public enum PlanProgress + { + Backlog = 0, + InProgress = 1, + Testing = 2, + Done = 3 + } +} From bc2bb3636b9c05380de56e0f2564c5e435ca9432 Mon Sep 17 00:00:00 2001 From: "DESKTOP-T0O5CDB\\DESK-555BD" Date: Fri, 19 Jan 2024 14:54:15 -0700 Subject: [PATCH 02/11] added backend for planner. --- Controllers/VehicleController.cs | 53 +++++++++ Enum/ImportMode.cs | 3 +- .../Implementations/PlanRecordDataAccess.cs | 57 +++++++++ External/Interfaces/IPlanRecordDataAccess.cs | 13 ++ Models/PlanRecord/PlanCostItem.cs | 8 ++ Models/PlanRecord/PlanRecord.cs | 19 +++ Models/PlanRecord/PlanRecordInput.cs | 32 +++++ .../UpgradeRecord.cs | 0 .../UpgradeReportInput.cs | 0 Program.cs | 1 + Views/Home/_Settings.cshtml | 13 +- Views/Vehicle/Index.cshtml | 7 ++ Views/Vehicle/_PlanRecords.cshtml | 112 ++++++++++++++++++ Views/Vehicle/_Report.cshtml | 6 +- wwwroot/css/site.css | 72 ++++++++--- wwwroot/js/vehicle.js | 18 +++ 16 files changed, 394 insertions(+), 20 deletions(-) create mode 100644 External/Implementations/PlanRecordDataAccess.cs create mode 100644 External/Interfaces/IPlanRecordDataAccess.cs create mode 100644 Models/PlanRecord/PlanCostItem.cs create mode 100644 Models/PlanRecord/PlanRecord.cs create mode 100644 Models/PlanRecord/PlanRecordInput.cs rename Models/{Upgrades => UpgradeRecord}/UpgradeRecord.cs (100%) rename Models/{Upgrades => UpgradeRecord}/UpgradeReportInput.cs (100%) create mode 100644 Views/Vehicle/_PlanRecords.cshtml diff --git a/Controllers/VehicleController.cs b/Controllers/VehicleController.cs index 5f4c24c..f4fc3fd 100644 --- a/Controllers/VehicleController.cs +++ b/Controllers/VehicleController.cs @@ -26,6 +26,7 @@ namespace CarCareTracker.Controllers private readonly IReminderRecordDataAccess _reminderRecordDataAccess; private readonly IUpgradeRecordDataAccess _upgradeRecordDataAccess; private readonly ISupplyRecordDataAccess _supplyRecordDataAccess; + private readonly IPlanRecordDataAccess _planRecordDataAccess; private readonly IWebHostEnvironment _webEnv; private readonly IConfigHelper _config; private readonly IFileHelper _fileHelper; @@ -48,6 +49,7 @@ namespace CarCareTracker.Controllers IReminderRecordDataAccess reminderRecordDataAccess, IUpgradeRecordDataAccess upgradeRecordDataAccess, ISupplyRecordDataAccess supplyRecordDataAccess, + IPlanRecordDataAccess planRecordDataAccess, IUserLogic userLogic, IWebHostEnvironment webEnv, IConfigHelper config) @@ -66,6 +68,7 @@ namespace CarCareTracker.Controllers _reminderRecordDataAccess = reminderRecordDataAccess; _upgradeRecordDataAccess = upgradeRecordDataAccess; _supplyRecordDataAccess = supplyRecordDataAccess; + _planRecordDataAccess = planRecordDataAccess; _userLogic = userLogic; _webEnv = webEnv; _config = config; @@ -134,6 +137,7 @@ namespace CarCareTracker.Controllers _noteDataAccess.DeleteAllNotesByVehicleId(vehicleId) && _reminderRecordDataAccess.DeleteAllReminderRecordsByVehicleId(vehicleId) && _upgradeRecordDataAccess.DeleteAllUpgradeRecordsByVehicleId(vehicleId) && + _planRecordDataAccess.DeleteAllPlanRecordsByVehicleId(vehicleId) && _supplyRecordDataAccess.DeleteAllSupplyRecordsByVehicleId(vehicleId) && _userLogic.DeleteAllAccessToVehicle(vehicleId) && _dataAccess.DeleteVehicle(vehicleId); @@ -1173,5 +1177,54 @@ namespace CarCareTracker.Controllers return Json(result); } #endregion + #region "Plan Records" + [TypeFilter(typeof(CollaboratorFilter))] + [HttpGet] + public IActionResult GetPlanRecordsByVehicleId(int vehicleId) + { + var result = _planRecordDataAccess.GetPlanRecordsByVehicleId(vehicleId); + return PartialView("_PlanRecords", result); + } + [HttpPost] + public IActionResult SavePlanRecordToVehicleId(PlanRecordInput planRecord) + { + //move files from temp. + planRecord.Files = planRecord.Files.Select(x => { return new UploadedFiles { Name = x.Name, Location = _fileHelper.MoveFileFromTemp(x.Location, "documents/") }; }).ToList(); + var result = _planRecordDataAccess.SavePlanRecordToVehicle(planRecord.ToPlanRecord()); + return Json(result); + } + [HttpGet] + public IActionResult GetAddPlanRecordPartialView() + { + return PartialView("_PlanRecordModal", new PlanRecordInput()); + } + [HttpGet] + public IActionResult GetPlanRecordForEditById(int planRecordId) + { + var result = _planRecordDataAccess.GetPlanRecordById(planRecordId); + //convert to Input object. + var convertedResult = new PlanRecordInput + { + Id = result.Id, + Description = result.Description, + DateCreated = result.DateCreated.ToShortDateString(), + DateModified = result.DateModified.ToShortDateString(), + ImportMode = result.ImportMode, + Priority = result.Priority, + Progress = result.Progress, + Costs = result.Costs, + Notes = result.Notes, + VehicleId = result.VehicleId, + Files = result.Files + }; + return PartialView("_PlanRecordModal", convertedResult); + } + [HttpPost] + public IActionResult DeletePlanRecordById(int planRecordId) + { + var result = _planRecordDataAccess.DeletePlanRecordById(planRecordId); + return Json(result); + } + #endregion } } diff --git a/Enum/ImportMode.cs b/Enum/ImportMode.cs index b2f5f01..845f54f 100644 --- a/Enum/ImportMode.cs +++ b/Enum/ImportMode.cs @@ -10,6 +10,7 @@ ReminderRecord = 5, NoteRecord = 6, SupplyRecord = 7, - Dashboard = 8 + Dashboard = 8, + PlanRecord = 9 } } diff --git a/External/Implementations/PlanRecordDataAccess.cs b/External/Implementations/PlanRecordDataAccess.cs new file mode 100644 index 0000000..227fd14 --- /dev/null +++ b/External/Implementations/PlanRecordDataAccess.cs @@ -0,0 +1,57 @@ +using CarCareTracker.External.Interfaces; +using CarCareTracker.Helper; +using CarCareTracker.Models; +using LiteDB; + +namespace CarCareTracker.External.Implementations +{ + public class PlanRecordDataAccess : IPlanRecordDataAccess + { + private static string dbName = StaticHelper.DbName; + private static string tableName = "planrecords"; + public List GetPlanRecordsByVehicleId(int vehicleId) + { + using (var db = new LiteDatabase(dbName)) + { + var table = db.GetCollection(tableName); + var planRecords = table.Find(Query.EQ(nameof(PlanRecord.VehicleId), vehicleId)); + return planRecords.ToList() ?? new List(); + }; + } + public PlanRecord GetPlanRecordById(int planRecordId) + { + using (var db = new LiteDatabase(dbName)) + { + var table = db.GetCollection(tableName); + return table.FindById(planRecordId); + }; + } + public bool DeletePlanRecordById(int planRecordId) + { + using (var db = new LiteDatabase(dbName)) + { + var table = db.GetCollection(tableName); + table.Delete(planRecordId); + return true; + }; + } + public bool SavePlanRecordToVehicle(PlanRecord planRecord) + { + using (var db = new LiteDatabase(dbName)) + { + var table = db.GetCollection(tableName); + table.Upsert(planRecord); + return true; + }; + } + public bool DeleteAllPlanRecordsByVehicleId(int vehicleId) + { + using (var db = new LiteDatabase(dbName)) + { + var table = db.GetCollection(tableName); + var planRecords = table.DeleteMany(Query.EQ(nameof(PlanRecord.VehicleId), vehicleId)); + return true; + }; + } + } +} diff --git a/External/Interfaces/IPlanRecordDataAccess.cs b/External/Interfaces/IPlanRecordDataAccess.cs new file mode 100644 index 0000000..1768801 --- /dev/null +++ b/External/Interfaces/IPlanRecordDataAccess.cs @@ -0,0 +1,13 @@ +using CarCareTracker.Models; + +namespace CarCareTracker.External.Interfaces +{ + public interface IPlanRecordDataAccess + { + public List GetPlanRecordsByVehicleId(int vehicleId); + public PlanRecord GetPlanRecordById(int planRecordId); + public bool DeletePlanRecordById(int planRecordId); + public bool SavePlanRecordToVehicle(PlanRecord planRecord); + public bool DeleteAllPlanRecordsByVehicleId(int vehicleId); + } +} diff --git a/Models/PlanRecord/PlanCostItem.cs b/Models/PlanRecord/PlanCostItem.cs new file mode 100644 index 0000000..37bafa7 --- /dev/null +++ b/Models/PlanRecord/PlanCostItem.cs @@ -0,0 +1,8 @@ +namespace CarCareTracker.Models +{ + public class PlanCostItem + { + public string CostName { get; set; } + public decimal CostAmount { get; set; } + } +} diff --git a/Models/PlanRecord/PlanRecord.cs b/Models/PlanRecord/PlanRecord.cs new file mode 100644 index 0000000..687f21a --- /dev/null +++ b/Models/PlanRecord/PlanRecord.cs @@ -0,0 +1,19 @@ +using CarCareTracker.Enum; + +namespace CarCareTracker.Models +{ + public class PlanRecord + { + public int Id { get; set; } + public int VehicleId { get; set; } + public DateTime DateCreated { get; set; } + public DateTime DateModified { get; set; } + public string Description { get; set; } + public string Notes { get; set; } + public List Files { get; set; } = new List(); + public ImportMode ImportMode { get; set; } + public PlanPriority Priority { get; set; } + public PlanProgress Progress { get; set; } + public List Costs { get; set; } = new List(); + } +} diff --git a/Models/PlanRecord/PlanRecordInput.cs b/Models/PlanRecord/PlanRecordInput.cs new file mode 100644 index 0000000..95dcc7b --- /dev/null +++ b/Models/PlanRecord/PlanRecordInput.cs @@ -0,0 +1,32 @@ +using CarCareTracker.Enum; + +namespace CarCareTracker.Models +{ + public class PlanRecordInput + { + public int Id { get; set; } + public int VehicleId { get; set; } + public string DateCreated { get; set; } = DateTime.Now.ToShortDateString(); + public string DateModified { get; set; } = DateTime.Now.ToShortDateString(); + public string Description { get; set; } + public string Notes { get; set; } + public List Files { get; set; } = new List(); + public ImportMode ImportMode { get; set; } + public PlanPriority Priority { get; set; } + public PlanProgress Progress { get; set; } + public List Costs { get; set; } = new List(); + public PlanRecord ToPlanRecord() { return new PlanRecord { + Id = Id, + VehicleId = VehicleId, + DateCreated = DateTime.Parse(DateCreated), + DateModified = DateTime.Parse(DateModified), + Description = Description, + Notes = Notes, + Files = Files, + ImportMode = ImportMode, + Costs = Costs, + Priority = Priority, + Progress = Progress + }; } + } +} diff --git a/Models/Upgrades/UpgradeRecord.cs b/Models/UpgradeRecord/UpgradeRecord.cs similarity index 100% rename from Models/Upgrades/UpgradeRecord.cs rename to Models/UpgradeRecord/UpgradeRecord.cs diff --git a/Models/Upgrades/UpgradeReportInput.cs b/Models/UpgradeRecord/UpgradeReportInput.cs similarity index 100% rename from Models/Upgrades/UpgradeReportInput.cs rename to Models/UpgradeRecord/UpgradeReportInput.cs diff --git a/Program.cs b/Program.cs index 571bd42..12a4140 100644 --- a/Program.cs +++ b/Program.cs @@ -23,6 +23,7 @@ builder.Services.AddSingleton(); builder.Services.AddSingleton(); builder.Services.AddSingleton(); builder.Services.AddSingleton(); +builder.Services.AddSingleton(); //configure helpers builder.Services.AddSingleton(); diff --git a/Views/Home/_Settings.cshtml b/Views/Home/_Settings.cshtml index eb462a0..522d89c 100644 --- a/Views/Home/_Settings.cshtml +++ b/Views/Home/_Settings.cshtml @@ -51,13 +51,13 @@
  • - - -
  • -
  • +
  • + + +
  • @@ -90,6 +90,10 @@
  • +
  • + + +
@@ -106,6 +110,7 @@ Notes Reminders Supplies + Planner @if (User.IsInRole(nameof(UserData.IsRootUser))) diff --git a/Views/Vehicle/Index.cshtml b/Views/Vehicle/Index.cshtml index 5bfba4c..164d291 100644 --- a/Views/Vehicle/Index.cshtml +++ b/Views/Vehicle/Index.cshtml @@ -46,6 +46,9 @@ + @@ -91,6 +94,9 @@ + @@ -117,6 +123,7 @@
+