Add vehicle service controller and view
This commit is contained in:
@@ -0,0 +1,47 @@
|
|||||||
|
using System;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Web.Mvc;
|
||||||
|
using MileageTraker.Web.Attributes;
|
||||||
|
using MileageTraker.Web.ViewModels.VehicleService;
|
||||||
|
|
||||||
|
namespace MileageTraker.Web.Controllers
|
||||||
|
{
|
||||||
|
[Authorize(Roles = "Administrator, Developer")]
|
||||||
|
public class VehicleServiceController : ControllerBase
|
||||||
|
{
|
||||||
|
public ActionResult Index(VehicleServiceQueryViewModel query)
|
||||||
|
{
|
||||||
|
var vehicleServices = DataService.GetVehicleServices();
|
||||||
|
var viewModel = new VehicleServiceResultsViewModel
|
||||||
|
{
|
||||||
|
ServiceItems = vehicleServices.Select(s => new VehicleServiceViewModel(s))
|
||||||
|
};
|
||||||
|
return View(viewModel);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ActionResult Create()
|
||||||
|
{
|
||||||
|
return View();
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpPost]
|
||||||
|
[ActionLog]
|
||||||
|
public ActionResult Create(VehicleServiceViewModel viewModel)
|
||||||
|
{
|
||||||
|
if (ModelState.IsValid)
|
||||||
|
{
|
||||||
|
var vehicleService = viewModel.GetVehicleService();
|
||||||
|
|
||||||
|
vehicleService.Vehicle = DataService.GetVehicle(viewModel.VehicleId);
|
||||||
|
DataService.AddVehicleService(vehicleService);
|
||||||
|
|
||||||
|
TempData["StatusMessage-Type"] = "alert-success";
|
||||||
|
TempData["StatusMessage"] =
|
||||||
|
string.Format("Vehicle Service for vehicle {0} created", viewModel.VehicleId);
|
||||||
|
return RedirectToAction("Index");
|
||||||
|
}
|
||||||
|
|
||||||
|
return View(viewModel);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -803,5 +803,39 @@ namespace MileageTraker.Web.DAL
|
|||||||
return ym.OrderByDescending(dt => dt).ToList();
|
return ym.OrderByDescending(dt => dt).ToList();
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
#region Vehicle Service
|
||||||
|
public void AddVehicleService(VehicleService vehicleService)
|
||||||
|
{
|
||||||
|
_db.VehicleServices.Add(vehicleService);
|
||||||
|
_db.SaveChanges();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void UpdateVehicleService(VehicleService vehicleService)
|
||||||
|
{
|
||||||
|
_db.Entry(vehicleService).State = EntityState.Modified;
|
||||||
|
_db.SaveChanges();
|
||||||
|
}
|
||||||
|
|
||||||
|
public IEnumerable<VehicleService> GetVehicleServices()
|
||||||
|
{
|
||||||
|
var vehicleServices = _db.VehicleServices;
|
||||||
|
return vehicleServices;
|
||||||
|
}
|
||||||
|
|
||||||
|
public VehicleService GetVehicleServices(string id)
|
||||||
|
{
|
||||||
|
return _db.VehicleServices.Find(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void DeleteVehicleService(int id)
|
||||||
|
{
|
||||||
|
var vehicleService = _db.VehicleServices.Find(id);
|
||||||
|
|
||||||
|
_db.VehicleServices.Remove(vehicleService);
|
||||||
|
_db.SaveChanges();
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -50,6 +50,7 @@ namespace MileageTraker.Web.Models
|
|||||||
|
|
||||||
[Required]
|
[Required]
|
||||||
[InputSize("small")]
|
[InputSize("small")]
|
||||||
|
[Units("$")]
|
||||||
public decimal Price { get; set; }
|
public decimal Price { get; set; }
|
||||||
|
|
||||||
[Required]
|
[Required]
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
$(function () {
|
$(function () {
|
||||||
$('.enable-javascript').show();
|
$('.enable-javascript').show();
|
||||||
|
|
||||||
$("input#Date, input#InactiveDate").datepicker({ maxDate: '+0d' });
|
$("input#Date, input#InactiveDate, input#InvoiceDate").datepicker({ maxDate: '+0d' });
|
||||||
|
|
||||||
$("input#CityName").autocomplete({
|
$("input#CityName").autocomplete({
|
||||||
source: "/City/Autocomplete",
|
source: "/City/Autocomplete",
|
||||||
|
|||||||
@@ -0,0 +1,39 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace MileageTraker.Web.ViewModels.VehicleService
|
||||||
|
{
|
||||||
|
public class VehicleServiceQueryViewModel
|
||||||
|
{
|
||||||
|
public int? Year { get; set; }
|
||||||
|
public int? Month { get; set; }
|
||||||
|
|
||||||
|
public string YearMonthStart {get
|
||||||
|
{
|
||||||
|
return string.Format("{0}-{1:00}", Year, Month);
|
||||||
|
}}
|
||||||
|
|
||||||
|
public override string ToString()
|
||||||
|
{
|
||||||
|
var v = new List<string>();
|
||||||
|
|
||||||
|
if (Year.HasValue && Month.HasValue)
|
||||||
|
{
|
||||||
|
var str = YearMonthStart;
|
||||||
|
|
||||||
|
v.Add(str);
|
||||||
|
}
|
||||||
|
else if (Year.HasValue)
|
||||||
|
{
|
||||||
|
v.Add(Year.ToString());
|
||||||
|
}
|
||||||
|
|
||||||
|
return String.Join("_", v).Replace(' ', '-');
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool HasParameters()
|
||||||
|
{
|
||||||
|
return Year.HasValue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace MileageTraker.Web.ViewModels.VehicleService
|
||||||
|
{
|
||||||
|
public class VehicleServiceResultsViewModel
|
||||||
|
{
|
||||||
|
public IEnumerable<VehicleServiceViewModel> ServiceItems { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,67 @@
|
|||||||
|
using System;
|
||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using System.Web.Mvc;
|
||||||
|
using AutoMapper;
|
||||||
|
using MileageTraker.Web.Attributes;
|
||||||
|
|
||||||
|
namespace MileageTraker.Web.ViewModels.VehicleService
|
||||||
|
{
|
||||||
|
public class VehicleServiceViewModel
|
||||||
|
{
|
||||||
|
[HiddenInput(DisplayValue = false)]
|
||||||
|
public int? VehicleServiceId { get; set; }
|
||||||
|
|
||||||
|
[Required]
|
||||||
|
[Remote("Exists", "Vehicle", ErrorMessage = "ID not found")]
|
||||||
|
[StringLength(6, MinimumLength = 4, ErrorMessage = "Must be at least a 4 digit number")]
|
||||||
|
[Display(Name = "Vehicle ID")]
|
||||||
|
[RegularExpression(@"\d+", ErrorMessage = "Vehicle ID must be all numbers")]
|
||||||
|
[InputSize("mini")]
|
||||||
|
public string VehicleId { get; set; }
|
||||||
|
|
||||||
|
[DataType(DataType.DateTime)]
|
||||||
|
[DisplayFormatAttribute(ApplyFormatInEditMode = true, DataFormatString = "{0:d}")]
|
||||||
|
[FormatHint("mm/dd/yyyy")]
|
||||||
|
[InputSize("small")]
|
||||||
|
public DateTime? InvoiceDate { get; set; }
|
||||||
|
|
||||||
|
[Required]
|
||||||
|
[StringLength(64, MinimumLength = 3, ErrorMessage = "Minimum 3 characters")]
|
||||||
|
public string ServiceCenterName { get; set; }
|
||||||
|
|
||||||
|
[Required]
|
||||||
|
[StringLength(32)]
|
||||||
|
[InputSize("small")]
|
||||||
|
public string InvoiceNumber { get; set; }
|
||||||
|
|
||||||
|
[Required]
|
||||||
|
[InputSize("small")]
|
||||||
|
[Units("$")]
|
||||||
|
public decimal Price { get; set; }
|
||||||
|
|
||||||
|
[StringLength(64, MinimumLength = 3, ErrorMessage = "Minimum 3 characters")]
|
||||||
|
public string Description { get; set; }
|
||||||
|
|
||||||
|
static VehicleServiceViewModel()
|
||||||
|
{
|
||||||
|
Mapper.CreateMap<VehicleServiceViewModel, Models.VehicleService>();
|
||||||
|
Mapper.CreateMap<Models.VehicleService, VehicleServiceViewModel>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public VehicleServiceViewModel(Models.VehicleService vehicleService)
|
||||||
|
{
|
||||||
|
Mapper.Map(vehicleService, this);
|
||||||
|
}
|
||||||
|
|
||||||
|
public VehicleServiceViewModel()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public Models.VehicleService GetVehicleService()
|
||||||
|
{
|
||||||
|
var vehicleService = new Models.VehicleService();
|
||||||
|
Mapper.Map(this, vehicleService);
|
||||||
|
return vehicleService;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -36,7 +36,13 @@
|
|||||||
@if (User.IsInRole("Developer") || User.IsInRole("Administrator"))
|
@if (User.IsInRole("Developer") || User.IsInRole("Administrator"))
|
||||||
{
|
{
|
||||||
<li id="log-nav">@Html.ActionLink("Logs", "Index", "Log")</li>
|
<li id="log-nav">@Html.ActionLink("Logs", "Index", "Log")</li>
|
||||||
<li id="vehicle-nav">@Html.ActionLink("Vehicles", "Index", "Vehicle")</li>
|
<li id="vehicle-nav" class="dropdown">
|
||||||
|
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Vehicles <span class="caret"></span></a>
|
||||||
|
<ul class="dropdown-menu">
|
||||||
|
<li>@Html.ActionLink("Vehicles", "Index", "Vehicle")</li>
|
||||||
|
<li>@Html.ActionLink("Vehicle Service", "Index", "VehicleService")</li>
|
||||||
|
</ul>
|
||||||
|
</li>
|
||||||
<li id="fuellog-nav">@Html.ActionLink("Fuel Logs", "Index", "FuelLog")</li>
|
<li id="fuellog-nav">@Html.ActionLink("Fuel Logs", "Index", "FuelLog")</li>
|
||||||
<li id="user-nav">@Html.ActionLink("Users", "Index", "User")</li>
|
<li id="user-nav">@Html.ActionLink("Users", "Index", "User")</li>
|
||||||
<li id="config-nav" class="dropdown">
|
<li id="config-nav" class="dropdown">
|
||||||
|
|||||||
@@ -0,0 +1,19 @@
|
|||||||
|
@model MileageTraker.Web.ViewModels.VehicleService.VehicleServiceViewModel
|
||||||
|
|
||||||
|
@{
|
||||||
|
ViewBag.Title = "Create Vehicle Service";
|
||||||
|
}
|
||||||
|
|
||||||
|
<h2 class="center-content"><i class="fa fa-wrench"></i> @ViewBag.Title</h2>
|
||||||
|
|
||||||
|
@using (Html.BeginForm("Create", "VehicleService", FormMethod.Post, new { @class = "form-horizontal well center-content" }))
|
||||||
|
{
|
||||||
|
@Html.Partial("_ValidationSummary")
|
||||||
|
<fieldset>
|
||||||
|
<legend></legend>
|
||||||
|
@Html.EditorForModel()
|
||||||
|
<div class="form-actions">
|
||||||
|
<input type="submit" value="Create" class="btn btn-primary" />
|
||||||
|
</div>
|
||||||
|
</fieldset>
|
||||||
|
}
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
@model MileageTraker.Web.ViewModels.VehicleService.VehicleServiceResultsViewModel
|
||||||
|
|
||||||
|
@{
|
||||||
|
ViewBag.Title = "Vehicle Service";
|
||||||
|
var grid = new WebGrid(Model.ServiceItems, rowsPerPage: 45);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Html.Partial("_StatusMessage")
|
||||||
|
|
||||||
|
<h2 id="vehicle-title"><i class="fa fa-wrench"></i> @ViewBag.Title</h2>
|
||||||
|
|
||||||
|
<div class="btn-toolbar pull-left">
|
||||||
|
@Html.ActionLink("Add Service", "Create", null, new{@class="btn"})
|
||||||
|
@Html.ActionLink("Export", "Export", null, new{@class="btn"})
|
||||||
|
</div>
|
||||||
|
|
||||||
|
@grid.GetHtml(columns:
|
||||||
|
grid.Columns(
|
||||||
|
grid.Column("InvoiceDate", "Invoice Date"),
|
||||||
|
grid.Column("VehicleID", "Vehicle Id"),
|
||||||
|
grid.Column("ServiceCenterName", "Service Center Name"),
|
||||||
|
grid.Column("Price", "Price"),
|
||||||
|
grid.Column("Description", "Description"),
|
||||||
|
grid.Column(format:
|
||||||
|
@<div class='btn-group'>
|
||||||
|
@Html.ActionLink("Details / Edit", "Details", new { id = item.VehicleServiceId }, new { @class = "btn btn-mini" })
|
||||||
|
</div>)
|
||||||
|
),
|
||||||
|
htmlAttributes: new { @class = "table table-striped table-bordered table-hover table-condensed"},
|
||||||
|
numericLinksCount: 20
|
||||||
|
)
|
||||||
@@ -145,6 +145,7 @@
|
|||||||
<Compile Include="Controllers\CityController.cs" />
|
<Compile Include="Controllers\CityController.cs" />
|
||||||
<Compile Include="Controllers\ControllerBase.cs" />
|
<Compile Include="Controllers\ControllerBase.cs" />
|
||||||
<Compile Include="Controllers\FuelLogController.cs" />
|
<Compile Include="Controllers\FuelLogController.cs" />
|
||||||
|
<Compile Include="Controllers\VehicleServiceController.cs" />
|
||||||
<Compile Include="Controllers\PurposeController.cs" />
|
<Compile Include="Controllers\PurposeController.cs" />
|
||||||
<Compile Include="Controllers\UserController.cs" />
|
<Compile Include="Controllers\UserController.cs" />
|
||||||
<Compile Include="DAL\CityNotFoundException.cs" />
|
<Compile Include="DAL\CityNotFoundException.cs" />
|
||||||
@@ -215,6 +216,10 @@
|
|||||||
<Compile Include="Migrations\201510021445490_LogVehicleRelationship.Designer.cs">
|
<Compile Include="Migrations\201510021445490_LogVehicleRelationship.Designer.cs">
|
||||||
<DependentUpon>201510021445490_LogVehicleRelationship.cs</DependentUpon>
|
<DependentUpon>201510021445490_LogVehicleRelationship.cs</DependentUpon>
|
||||||
</Compile>
|
</Compile>
|
||||||
|
<Compile Include="Migrations\201510070326593_VehicleService.cs" />
|
||||||
|
<Compile Include="Migrations\201510070326593_VehicleService.Designer.cs">
|
||||||
|
<DependentUpon>201510070326593_VehicleService.cs</DependentUpon>
|
||||||
|
</Compile>
|
||||||
<Compile Include="Migrations\Configuration.cs" />
|
<Compile Include="Migrations\Configuration.cs" />
|
||||||
<Compile Include="Models\DomainRules.cs" />
|
<Compile Include="Models\DomainRules.cs" />
|
||||||
<Compile Include="Models\FuelLog.cs" />
|
<Compile Include="Models\FuelLog.cs" />
|
||||||
@@ -248,6 +253,10 @@
|
|||||||
<Compile Include="ViewModels\Log\LogViewModel.cs" />
|
<Compile Include="ViewModels\Log\LogViewModel.cs" />
|
||||||
<Compile Include="ViewModels\Log\LogIndexViewModel.cs" />
|
<Compile Include="ViewModels\Log\LogIndexViewModel.cs" />
|
||||||
<Compile Include="ViewModels\Log\LogPartialDetails.cs" />
|
<Compile Include="ViewModels\Log\LogPartialDetails.cs" />
|
||||||
|
<Compile Include="Models\VehicleService.cs" />
|
||||||
|
<Compile Include="ViewModels\VehicleService\VehicleServiceQueryViewModel.cs" />
|
||||||
|
<Compile Include="ViewModels\VehicleService\VehicleServiceResultsViewModel.cs" />
|
||||||
|
<Compile Include="ViewModels\VehicleService\VehicleServiceViewModel.cs" />
|
||||||
<Compile Include="ViewModels\Vehicle\VehicleResultsViewModel.cs" />
|
<Compile Include="ViewModels\Vehicle\VehicleResultsViewModel.cs" />
|
||||||
<Compile Include="ViewModels\SelectListViewModel.cs" />
|
<Compile Include="ViewModels\SelectListViewModel.cs" />
|
||||||
<Compile Include="ViewModels\User\ExportUserViewModel.cs" />
|
<Compile Include="ViewModels\User\ExportUserViewModel.cs" />
|
||||||
@@ -319,6 +328,8 @@
|
|||||||
<Content Include="Views\FuelLog\Match.cshtml" />
|
<Content Include="Views\FuelLog\Match.cshtml" />
|
||||||
<Content Include="Views\FuelLog\MatchLogViewModelPartial.cshtml" />
|
<Content Include="Views\FuelLog\MatchLogViewModelPartial.cshtml" />
|
||||||
<Content Include="Views\Shared\EditorTemplates\FuelLogResultsViewModel.cshtml" />
|
<Content Include="Views\Shared\EditorTemplates\FuelLogResultsViewModel.cshtml" />
|
||||||
|
<Content Include="Views\VehicleService\Index.cshtml" />
|
||||||
|
<Content Include="Views\VehicleService\Create.cshtml" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Content Include="Content\Account.Login.css" />
|
<Content Include="Content\Account.Login.css" />
|
||||||
@@ -551,6 +562,9 @@
|
|||||||
<EmbeddedResource Include="Migrations\201510021445490_LogVehicleRelationship.resx">
|
<EmbeddedResource Include="Migrations\201510021445490_LogVehicleRelationship.resx">
|
||||||
<DependentUpon>201510021445490_LogVehicleRelationship.cs</DependentUpon>
|
<DependentUpon>201510021445490_LogVehicleRelationship.cs</DependentUpon>
|
||||||
</EmbeddedResource>
|
</EmbeddedResource>
|
||||||
|
<EmbeddedResource Include="Migrations\201510070326593_VehicleService.resx">
|
||||||
|
<DependentUpon>201510070326593_VehicleService.cs</DependentUpon>
|
||||||
|
</EmbeddedResource>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
|
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
|
||||||
|
|||||||
Reference in New Issue
Block a user