-
-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #39 from hargata/Hargata/upgradestab
Upgrades Tab
- Loading branch information
Showing
13 changed files
with
468 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
using CarCareTracker.External.Interfaces; | ||
using CarCareTracker.Helper; | ||
using CarCareTracker.Models; | ||
using LiteDB; | ||
|
||
namespace CarCareTracker.External.Implementations | ||
{ | ||
public class UpgradeRecordDataAccess : IUpgradeRecordDataAccess | ||
{ | ||
private static string dbName = StaticHelper.DbName; | ||
private static string tableName = "upgraderecords"; | ||
public List<UpgradeRecord> GetUpgradeRecordsByVehicleId(int vehicleId) | ||
{ | ||
using (var db = new LiteDatabase(dbName)) | ||
{ | ||
var table = db.GetCollection<UpgradeRecord>(tableName); | ||
var upgradeRecords = table.Find(Query.EQ(nameof(UpgradeRecord.VehicleId), vehicleId)); | ||
return upgradeRecords.ToList() ?? new List<UpgradeRecord>(); | ||
}; | ||
} | ||
public UpgradeRecord GetUpgradeRecordById(int upgradeRecordId) | ||
{ | ||
using (var db = new LiteDatabase(dbName)) | ||
{ | ||
var table = db.GetCollection<UpgradeRecord>(tableName); | ||
return table.FindById(upgradeRecordId); | ||
}; | ||
} | ||
public bool DeleteUpgradeRecordById(int upgradeRecordId) | ||
{ | ||
using (var db = new LiteDatabase(dbName)) | ||
{ | ||
var table = db.GetCollection<UpgradeRecord>(tableName); | ||
table.Delete(upgradeRecordId); | ||
return true; | ||
}; | ||
} | ||
public bool SaveUpgradeRecordToVehicle(UpgradeRecord upgradeRecord) | ||
{ | ||
using (var db = new LiteDatabase(dbName)) | ||
{ | ||
var table = db.GetCollection<UpgradeRecord>(tableName); | ||
table.Upsert(upgradeRecord); | ||
return true; | ||
}; | ||
} | ||
public bool DeleteAllUpgradeRecordsByVehicleId(int vehicleId) | ||
{ | ||
using (var db = new LiteDatabase(dbName)) | ||
{ | ||
var table = db.GetCollection<UpgradeRecord>(tableName); | ||
var upgradeRecords = table.DeleteMany(Query.EQ(nameof(UpgradeRecord.VehicleId), vehicleId)); | ||
return true; | ||
}; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
using CarCareTracker.Models; | ||
|
||
namespace CarCareTracker.External.Interfaces | ||
{ | ||
public interface IUpgradeRecordDataAccess | ||
{ | ||
public List<UpgradeRecord> GetUpgradeRecordsByVehicleId(int vehicleId); | ||
public UpgradeRecord GetUpgradeRecordById(int upgradeRecordId); | ||
public bool DeleteUpgradeRecordById(int upgradeRecordId); | ||
public bool SaveUpgradeRecordToVehicle(UpgradeRecord upgradeRecord); | ||
public bool DeleteAllUpgradeRecordsByVehicleId(int vehicleId); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
namespace CarCareTracker.Models | ||
{ | ||
public class UpgradeRecord | ||
{ | ||
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>(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
namespace CarCareTracker.Models | ||
{ | ||
public class UpgradeRecordInput | ||
{ | ||
public int Id { get; set; } | ||
public int VehicleId { get; set; } | ||
public string 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>(); | ||
public UpgradeRecord ToUpgradeRecord() { return new UpgradeRecord { Id = Id, VehicleId = VehicleId, Date = DateTime.Parse(Date), Cost = Cost, Mileage = Mileage, Description = Description, Notes = Notes, Files = Files }; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
@model UpgradeRecordInput | ||
@{ | ||
var isNew = Model.Id == 0; | ||
} | ||
<div class="modal-header"> | ||
<h5 class="modal-title">@(isNew ? "Add New Upgrade Record" : "Edit Upgrade Record")</h5> | ||
<button type="button" class="btn-close" onclick="hideAddUpgradeRecordModal()" aria-label="Close"></button> | ||
</div> | ||
<div class="modal-body"> | ||
<form> | ||
<div class="form-group"> | ||
<div class="row"> | ||
<div class="col-md-6 col-12"> | ||
<input type="text" id="workAroundInput" style="height:0px; width:0px; display:none;"> | ||
<label for="upgradeRecordDate">Date</label> | ||
<div class="input-group"> | ||
<input type="text" id="upgradeRecordDate" class="form-control" placeholder="Date upgrade/mods was installed" value="@Model.Date"> | ||
<span class="input-group-text"><i class="bi bi-calendar-event"></i></span> | ||
</div> | ||
<label for="upgradeRecordMileage">Odometer</label> | ||
<input type="number" id="upgradeRecordMileage" class="form-control" placeholder="Odometer reading when upgraded/modded" value="@(isNew ? "" : Model.Mileage)"> | ||
<label for="upgradeRecordDescription">Description</label> | ||
<input type="text" id="upgradeRecordDescription" class="form-control" placeholder="Description of item(s) upgraded/modded" value="@Model.Description"> | ||
<label for="upgradeRecordCost">Cost</label> | ||
<input type="number" id="upgradeRecordCost" class="form-control" placeholder="Cost of the upgrade/mods" value="@(isNew ? "" : Model.Cost)"> | ||
</div> | ||
<div class="col-md-6 col-12"> | ||
<label for="upgradeRecordNotes">Notes(optional)</label> | ||
<textarea id="upgradeRecordNotes" class="form-control" rows="5">@Model.Notes</textarea> | ||
@if (Model.Files.Any()) | ||
{ | ||
<div> | ||
@await Html.PartialAsync("_UploadedFiles", Model.Files) | ||
<label for="upgradeRecordFiles">Upload more documents</label> | ||
<input onChange="uploadVehicleFilesAsync(this)" type="file" multiple accept=".png,.jpg,.jpeg,.pdf,.xls,.xlsx,.docx" class="form-control-file" id="upgradeRecordFiles"> | ||
</div> | ||
} | ||
else | ||
{ | ||
@if (isNew) | ||
{ | ||
<div class="form-check"> | ||
<input class="form-check-input" type="checkbox" value="" id="addReminderCheck"> | ||
<label class="form-check-label" for="addReminderCheck"> | ||
Add Reminder | ||
</label> | ||
</div> | ||
} | ||
<label for="upgradeRecordFiles">Upload documents(optional)</label> | ||
<input onChange="uploadVehicleFilesAsync(this)" type="file" multiple accept=".png,.jpg,.jpeg,.pdf,.xls,.xlsx,.docx" class="form-control-file" id="upgradeRecordFiles"> | ||
} | ||
</div> | ||
</div> | ||
</div> | ||
</form> | ||
</div> | ||
<div class="modal-footer"> | ||
@if (!isNew) | ||
{ | ||
<button type="button" class="btn btn-danger" onclick="deleteUpgradeRecord(@Model.Id)" style="margin-right:auto;">Delete</button> | ||
} | ||
<button type="button" class="btn btn-secondary" onclick="hideAddUpgradeRecordModal()">Cancel</button> | ||
@if (isNew) | ||
{ | ||
<button type="button" class="btn btn-primary" onclick="saveUpgradeRecordToVehicle()">Add New Upgrade Record</button> | ||
} | ||
else if (!isNew) | ||
{ | ||
<button type="button" class="btn btn-primary" onclick="saveUpgradeRecordToVehicle(true)">Edit Upgrade Record</button> | ||
} | ||
</div> | ||
<script> | ||
var uploadedFiles = []; | ||
getUploadedFilesFromModel(); | ||
function getUploadedFilesFromModel() { | ||
@foreach (UploadedFiles filesUploaded in Model.Files) | ||
{ | ||
@:uploadedFiles.push({ name: "@filesUploaded.Name", location: "@filesUploaded.Location" }); | ||
} | ||
} | ||
function getUpgradeRecordModelData() { | ||
return { id: @Model.Id} | ||
} | ||
</script> |
Oops, something went wrong.