Add vehicle active/inactive state
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Web.Mvc;
|
||||
using MileageTraker.Web.Attributes;
|
||||
using MileageTraker.Web.DAL;
|
||||
@@ -10,10 +11,11 @@ namespace MileageTraker.Web.Controllers
|
||||
[Authorize(Roles = "Administrator, Developer")]
|
||||
public class VehicleController : ControllerBase
|
||||
{
|
||||
public ViewResult Index()
|
||||
public ViewResult Index(bool inactive = false)
|
||||
{
|
||||
var vehicles = DataService.GetVehicles();
|
||||
return View(vehicles);
|
||||
var vehicles = DataService.GetVehicles().Where(v => v.InactiveDate.HasValue == inactive);
|
||||
var viewModel = new VehicleResultsViewModel(vehicles, inactive);
|
||||
return View(viewModel);
|
||||
}
|
||||
|
||||
public ViewResult Details(string id)
|
||||
@@ -81,5 +83,39 @@ namespace MileageTraker.Web.Controllers
|
||||
var export = VehicleImporter.Export(vehicles);
|
||||
return File(export, "application/ms-excel", string.Format("ETHRAVehicles{0:yyyy-MM-dd}.xls", DateTime.Today));
|
||||
}
|
||||
|
||||
[ActionLog]
|
||||
public ActionResult SetInactive(string id)
|
||||
{
|
||||
var vehicle = DataService.GetVehicle(id);
|
||||
if (vehicle.InactiveDate.HasValue)
|
||||
{
|
||||
TempData["StatusMessage"] = "Vehicle already inactive";
|
||||
}
|
||||
else
|
||||
{
|
||||
vehicle.InactiveDate = DateTime.Now;
|
||||
DataService.UpdateVehicle(vehicle);
|
||||
TempData["StatusMessage"] = string.Format("Vehicle set inactive on {0:MM/dd/yyyy}", vehicle.InactiveDate.Value);
|
||||
}
|
||||
return RedirectToAction("Details", new {id});
|
||||
}
|
||||
|
||||
[ActionLog]
|
||||
public ActionResult SetActive(string id)
|
||||
{
|
||||
var vehicle = DataService.GetVehicle(id);
|
||||
if (!vehicle.InactiveDate.HasValue)
|
||||
{
|
||||
TempData["StatusMessage"] = "Vehicle is already active";
|
||||
}
|
||||
else
|
||||
{
|
||||
vehicle.InactiveDate = null;
|
||||
DataService.UpdateVehicle(vehicle);
|
||||
TempData["StatusMessage"] = string.Format("Vehicle reactivated");
|
||||
}
|
||||
return RedirectToAction("Details", new { id });
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user