Vehicle Service added for drivers
This commit is contained in:
@@ -75,9 +75,12 @@ namespace MileageTraker.Web.Controllers
|
||||
}
|
||||
|
||||
[AllowAnonymous]
|
||||
public JsonResult Exists(string vehicleId)
|
||||
public JsonResult Exists(string vehicleId, string serviceVehicleId)
|
||||
{
|
||||
var vehicle = DataService.GetVehicle(vehicleId);
|
||||
var vehicle =
|
||||
vehicleId != null
|
||||
? DataService.GetVehicle(vehicleId)
|
||||
: DataService.GetVehicle(serviceVehicleId);
|
||||
return Json(vehicle != null, JsonRequestBehavior.AllowGet);
|
||||
}
|
||||
|
||||
|
||||
@@ -12,9 +12,10 @@ using MileageTraker.Web.ViewModels.VehicleService;
|
||||
|
||||
namespace MileageTraker.Web.Controllers
|
||||
{
|
||||
[Authorize(Roles = "Administrator, Developer")]
|
||||
[Authorize(Roles = "Administrator, Developer, Driver")]
|
||||
public class VehicleServiceController : ControllerBase
|
||||
{
|
||||
[Authorize(Roles = "Administrator, Developer")]
|
||||
public ActionResult Index(VehicleServiceQueryViewModel query)
|
||||
{
|
||||
var validVehicleServiceYearMonths = DataService.GetValidVehicleServiceMonths();
|
||||
@@ -41,6 +42,7 @@ namespace MileageTraker.Web.Controllers
|
||||
return View(viewModel);
|
||||
}
|
||||
|
||||
[Authorize(Roles = "Administrator, Developer")]
|
||||
[ActionLog]
|
||||
public ActionResult Export(VehicleServiceQueryViewModel query)
|
||||
{
|
||||
@@ -61,6 +63,7 @@ namespace MileageTraker.Web.Controllers
|
||||
return File(export, "application/ms-excel", name + ".xls");
|
||||
}
|
||||
|
||||
[Authorize(Roles = "Administrator, Developer")]
|
||||
public ViewResult Details(int id)
|
||||
{
|
||||
var vehicleService = DataService.GetVehicleService(id);
|
||||
@@ -68,11 +71,13 @@ namespace MileageTraker.Web.Controllers
|
||||
return View(viewModel);
|
||||
}
|
||||
|
||||
[Authorize(Roles = "Administrator, Developer")]
|
||||
public ActionResult Create()
|
||||
{
|
||||
return View();
|
||||
}
|
||||
|
||||
[Authorize(Roles = "Administrator, Developer")]
|
||||
[HttpGet]
|
||||
[RequireRequestValue("vehicleId")]
|
||||
public ActionResult Create(string vehicleId)
|
||||
@@ -80,6 +85,13 @@ namespace MileageTraker.Web.Controllers
|
||||
return View(new VehicleServiceViewModel{VehicleId = vehicleId});
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[RequireRequestValue("serviceVehicleId")]
|
||||
public ActionResult CreateDriver(string serviceVehicleId)
|
||||
{
|
||||
return View ("Create", new VehicleServiceViewModel{VehicleId = serviceVehicleId });
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[ActionLog]
|
||||
public ActionResult Create(VehicleServiceViewModel viewModel)
|
||||
@@ -158,12 +170,19 @@ namespace MileageTraker.Web.Controllers
|
||||
{
|
||||
SetStatusMessage(string.Join(", ", status), StatusType.Success);
|
||||
}
|
||||
return RedirectToAction("Index");
|
||||
}
|
||||
|
||||
if (User.IsInRole("Administrator") || User.IsInRole("Developer"))
|
||||
{
|
||||
return RedirectToAction("Index");
|
||||
}
|
||||
|
||||
return RedirectToAction("Index", "CreateLog"); // for the drivers
|
||||
}
|
||||
|
||||
return View(viewModel);
|
||||
}
|
||||
|
||||
[Authorize(Roles = "Administrator, Developer")]
|
||||
private void RefreshServiceReminderViewModel(
|
||||
UpdateServiceRemindersViewModel viewModel, Vehicle vehicle, bool setDefaultSelectedServiceReminders = false)
|
||||
{
|
||||
@@ -186,6 +205,7 @@ namespace MileageTraker.Web.Controllers
|
||||
}
|
||||
}
|
||||
|
||||
[Authorize(Roles = "Administrator, Developer")]
|
||||
public ActionResult Edit(int id)
|
||||
{
|
||||
var vehicleService = DataService.GetVehicleService(id);
|
||||
@@ -193,6 +213,7 @@ namespace MileageTraker.Web.Controllers
|
||||
return View(viewModel);
|
||||
}
|
||||
|
||||
[Authorize(Roles = "Administrator, Developer")]
|
||||
public ActionResult Delete(int id)
|
||||
{
|
||||
var vehicleService = DataService.GetVehicleService(id);
|
||||
@@ -200,6 +221,7 @@ namespace MileageTraker.Web.Controllers
|
||||
return View(viewModel);
|
||||
}
|
||||
|
||||
[Authorize(Roles = "Administrator, Developer")]
|
||||
[HttpPost, ActionName("Delete")]
|
||||
[ActionLog]
|
||||
public ActionResult DeleteConfirmed(int id)
|
||||
@@ -210,6 +232,7 @@ namespace MileageTraker.Web.Controllers
|
||||
return RedirectToAction("Index");
|
||||
}
|
||||
|
||||
[Authorize(Roles = "Administrator, Developer")]
|
||||
[HttpPost]
|
||||
[ActionLog]
|
||||
public ActionResult Edit(VehicleServiceViewModel viewModel)
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Web.Mvc;
|
||||
using MileageTraker.Web.Attributes;
|
||||
using MileageTraker.Web.DAL;
|
||||
|
||||
namespace MileageTraker.Web.ViewModels.VehicleService
|
||||
{
|
||||
public class VehicleSelectViewModel : IValidatableObject
|
||||
{
|
||||
[Required(ErrorMessage = "Required")]
|
||||
[Remote("Exists", "Vehicle", ErrorMessage = "ID not found")]
|
||||
[StringLength(6, MinimumLength = 4, ErrorMessage = "Must be a 4 digit number")]
|
||||
[Display(Name = "Vehicle ID")]
|
||||
[InputSize("mini")]
|
||||
[RegularExpression(@"\d+", ErrorMessage = "Must be all numbers")]
|
||||
public string ServiceVehicleId { get; set; }
|
||||
|
||||
public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
|
||||
{
|
||||
using (var dataService = new DataService())
|
||||
{
|
||||
var inactiveDate = dataService.GetVehicle(ServiceVehicleId).InactiveDate;
|
||||
if (inactiveDate.HasValue)
|
||||
{
|
||||
yield return new ValidationResult(
|
||||
string.Format("Vehicle was set inactive on {0:MM/dd/yyyy}", inactiveDate.Value),
|
||||
new[] { "VehicleId" });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return string.Format("vehicle: {0}", ServiceVehicleId);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
@model MileageTraker.Web.ViewModels.CreateLog.CreateLogViewModel
|
||||
@using MileageTraker.Web.ViewModels.VehicleService
|
||||
@model MileageTraker.Web.ViewModels.CreateLog.CreateLogViewModel
|
||||
@{
|
||||
|
||||
ViewBag.Title = "Enter Mileage Log";
|
||||
@@ -24,6 +25,8 @@
|
||||
|
||||
</div>
|
||||
|
||||
@Html.Partial("VehicleSelect", new VehicleSelectViewModel())
|
||||
|
||||
<div class="center-content" style="text-align: center">
|
||||
@Html.ActionLink("Import", "ImportUpload", new {}, new { @class = "btn"})
|
||||
</div>
|
||||
@@ -0,0 +1,25 @@
|
||||
@model MileageTraker.Web.ViewModels.VehicleService.VehicleSelectViewModel
|
||||
|
||||
@using (Html.BeginForm("CreateDriver", "VehicleService", FormMethod.Post, new { @class = "form-horizontal well center-content" }))
|
||||
{
|
||||
<h5>Enter Vehicle Service</h5>
|
||||
<div class="control-group serviceVehicleId">
|
||||
<div class="row-fluid">
|
||||
<div class="span6">
|
||||
@Html.LabelFor(m => m.ServiceVehicleId, "Vehicle ID")
|
||||
</div>
|
||||
<div class="span4">
|
||||
@Html.TextBoxFor(m => m.ServiceVehicleId, new { @class = "input-mini" })
|
||||
|
||||
</div>
|
||||
<div class="span2">
|
||||
<input type="submit" value="Enter" class="btn btn-small" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="row-fluid">
|
||||
<div class="offset6">
|
||||
<span class="help-block">@Html.ValidationMessage("ServiceVehicleId")</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
@@ -166,6 +166,7 @@
|
||||
<Compile Include="Email\ServiceReminderEmailService.cs" />
|
||||
<Compile Include="Startup.cs" />
|
||||
<Compile Include="ViewModels\DriverMileageFlattenedViewModel.cs" />
|
||||
<Compile Include="ViewModels\VehicleService\VehicleSelectViewModel.cs" />
|
||||
<Compile Include="ViewModels\VehicleService\UpdateServiceRemindersViewModel.cs" />
|
||||
<Compile Include="Controllers\FuelLogController.cs" />
|
||||
<Compile Include="Controllers\ServiceReminderController.cs" />
|
||||
@@ -387,6 +388,7 @@
|
||||
<Content Include="Views\Shared\PageTitle.cshtml" />
|
||||
<Content Include="Views\VehicleService\Delete.cshtml" />
|
||||
<Content Include="Views\ServiceReminder\Delete.cshtml" />
|
||||
<Content Include="Views\CreateLog\VehicleSelect.cshtml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="Content\Account.Login.css" />
|
||||
|
||||
Reference in New Issue
Block a user