added functions to add and remove collaborators.

This commit is contained in:
DESKTOP-GENO133\IvanPlex
2024-01-13 21:18:58 -07:00
parent 4388df71f3
commit 2ae334d06d
6 changed files with 104 additions and 9 deletions

View File

@@ -1,4 +1,5 @@
using CarCareTracker.External.Interfaces;
using CarCareTracker.Filter;
using CarCareTracker.Helper;
using CarCareTracker.Models;
using Microsoft.AspNetCore.Authorization;
@@ -53,6 +54,7 @@ namespace CarCareTracker.Controllers
var result = _dataAccess.GetVehicles();
return Json(result);
}
[TypeFilter(typeof(CollaboratorFilter))]
[HttpGet]
[Route("/api/vehicle/servicerecords")]
public IActionResult ServiceRecords(int vehicleId)
@@ -61,6 +63,7 @@ namespace CarCareTracker.Controllers
var result = vehicleRecords.Select(x => new ServiceRecordExportModel { Date = x.Date.ToShortDateString(), Description = x.Description, Cost = x.Cost.ToString(), Notes = x.Notes, Odometer = x.Mileage.ToString() });
return Json(result);
}
[TypeFilter(typeof(CollaboratorFilter))]
[HttpGet]
[Route("/api/vehicle/repairrecords")]
public IActionResult RepairRecords(int vehicleId)
@@ -69,6 +72,7 @@ namespace CarCareTracker.Controllers
var result = vehicleRecords.Select(x => new ServiceRecordExportModel { Date = x.Date.ToShortDateString(), Description = x.Description, Cost = x.Cost.ToString(), Notes = x.Notes, Odometer = x.Mileage.ToString() });
return Json(result);
}
[TypeFilter(typeof(CollaboratorFilter))]
[HttpGet]
[Route("/api/vehicle/upgraderecords")]
public IActionResult UpgradeRecords(int vehicleId)
@@ -77,6 +81,7 @@ namespace CarCareTracker.Controllers
var result = vehicleRecords.Select(x => new ServiceRecordExportModel { Date = x.Date.ToShortDateString(), Description = x.Description, Cost = x.Cost.ToString(), Notes = x.Notes, Odometer = x.Mileage.ToString() });
return Json(result);
}
[TypeFilter(typeof(CollaboratorFilter))]
[HttpGet]
[Route("/api/vehicle/taxrecords")]
public IActionResult TaxRecords(int vehicleId)
@@ -84,6 +89,7 @@ namespace CarCareTracker.Controllers
var result = _taxRecordDataAccess.GetTaxRecordsByVehicleId(vehicleId);
return Json(result);
}
[TypeFilter(typeof(CollaboratorFilter))]
[HttpGet]
[Route("/api/vehicle/gasrecords")]
public IActionResult GasRecords(int vehicleId, bool useMPG, bool useUKMPG)
@@ -92,6 +98,7 @@ namespace CarCareTracker.Controllers
var result = _gasHelper.GetGasRecordViewModels(vehicleRecords, useMPG, useUKMPG).Select(x => new GasRecordExportModel { Date = x.Date, Odometer = x.Mileage.ToString(), Cost = x.Cost.ToString(), FuelConsumed = x.Gallons.ToString(), FuelEconomy = x.MilesPerGallon.ToString()});
return Json(result);
}
[TypeFilter(typeof(CollaboratorFilter))]
[HttpGet]
[Route("/api/vehicle/reminders")]
public IActionResult Reminders(int vehicleId)

View File

@@ -11,9 +11,11 @@ namespace CarCareTracker.Controllers
public class AdminController : Controller
{
private ILoginLogic _loginLogic;
public AdminController(ILoginLogic loginLogic)
private IUserLogic _userLogic;
public AdminController(ILoginLogic loginLogic, IUserLogic userLogic)
{
_loginLogic = loginLogic;
_userLogic = userLogic;
}
public IActionResult Index()
{
@@ -36,7 +38,7 @@ namespace CarCareTracker.Controllers
}
public IActionResult DeleteUser(int userId)
{
var result =_loginLogic.DeleteUser(userId);
var result =_userLogic.DeleteAllAccessToUser(userId) && _loginLogic.DeleteUser(userId);
return Json(result);
}
}

View File

@@ -688,6 +688,20 @@ namespace CarCareTracker.Controllers
return PartialView("_Collaborators", result);
}
[TypeFilter(typeof(CollaboratorFilter))]
[HttpPost]
public IActionResult AddCollaboratorsToVehicle(int vehicleId, string username)
{
var result = _userLogic.AddCollaboratorToVehicle(vehicleId, username);
return Json(result);
}
[TypeFilter(typeof(CollaboratorFilter))]
[HttpPost]
public IActionResult DeleteCollaboratorFromVehicle(int userId, int vehicleId)
{
var result = _userLogic.DeleteCollaboratorFromVehicle(userId, vehicleId);
return Json(result);
}
[TypeFilter(typeof(CollaboratorFilter))]
[HttpGet]
public IActionResult GetCostMakeUpForVehicle(int vehicleId, int year = 0)
{