diff --git a/Web/Controllers/VehicleController.cs b/Web/Controllers/VehicleController.cs index bcaed39..052b0ca 100644 --- a/Web/Controllers/VehicleController.cs +++ b/Web/Controllers/VehicleController.cs @@ -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 }); + } } } \ No newline at end of file diff --git a/Web/Migrations/201506181329243_VehicleInactiveDate.Designer.cs b/Web/Migrations/201506181329243_VehicleInactiveDate.Designer.cs new file mode 100644 index 0000000..82d3109 --- /dev/null +++ b/Web/Migrations/201506181329243_VehicleInactiveDate.Designer.cs @@ -0,0 +1,24 @@ +// +namespace MileageTraker.Web.Migrations +{ + using System.Data.Entity.Migrations; + using System.Data.Entity.Migrations.Infrastructure; + + public sealed partial class VehicleInactiveDate : IMigrationMetadata + { + string IMigrationMetadata.Id + { + get { return "201506181329243_VehicleInactiveDate"; } + } + + string IMigrationMetadata.Source + { + get { return null; } + } + + string IMigrationMetadata.Target + { + get { return "H4sIAAAAAAAEANVdzW7kuBG+B8g7NPqUBNhu21kMZgf2Lrzt8cTI2B5Me2eRk0FL7DYx+umVKMd+thzySHmFkPrlv0hKrbZvblL8WCyWqoqsUvl///nv6S/PcTR7glmO0uRsfrw4ms9gEqQhSrZn8wJvfng//+XnP//p9GMYP8++Nc+d0OfIyCQ/mz9ivPuwXObBI4xBvohRkKV5usGLII2XIEyXJ0dH75fHR0tIIOYEazY7/VokGMWw/EF+rtIkgDtcgOg6DWGU1+2kZ12izm5ADPMdCODZ/BpFEGzhXQa+w2zxO3xYkNEYPuP57DxCgBC0htHGkbqjnyh183bekqZ4F8Hnu5cdLKdvZ/6cbmnj7xnY7WDGjiGjvmQpacQv9ZBvICrgfEafP5tfJfjvJ/PZTRFF4CEiDRsQ5aR3yU67ZOZl2z8ShuEXhhpChjD3P+EL18CQ8xVuumFXIT8nnVUcKy6kHmZeyO7dhzVOM/gJJjADGIZfAMYwI/JyFcKS/npbPuze2e3MT8ujE7ozS5AkKQaYCJ9Eu8hy+IiCCHbUrnFGhHk+u0TPMPwMky1+bCm+Bs9Ny7v57LcEEcknQ3BGd824UfLEH5PwNkxjSFbssuNKXtPhLf1EnBdq2XNFXpEtoH+5subHoby5STHMx5y1+m2e9BPIvxRZ8Ahy2ArDRVqQ8c70XxBpbiHI33codgdZZZC+FINx1ilZlesekj8HsvO3HGb/SHN8HoYZzF13c5z5z7dEj0w+c61SvmTwCaVFbtaFSsAb8IS2pfpSLGo++wqjsjN/RLv6hSeT3Fedl1kaf02jSjGUbfetBKRCxx3IthDbT0/ej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Z8kbZ6kQrUuq6RtqyRCtW14FFfvSPVHB4FkUz1kFRTOBRLetGWSlIBK4soqbiu2c+uS8d95b7uo3oRS2H3Dbj8EgqOkZAJ2ZOAZ7mMwUWKFCIpfYV2mKXtrxhRH8Hqo9Doixy3tJCqnNABdk5Rv8xUCU2TNyu5qeLXsaaFiVqE/yhg1CU2RZiMS1RnMQ9SKGMt0aEElJy8S7wJ5v/PEnemDFg0EDQ5OYEB50e0z1wlm7TxaQSKmkfEmCDEICROxnmG0QYEmHTTdJuyjnKZ/UlTph5geJXcFnhXYLJkGD9EnM2hbpFp/rLOFU/z6W0Z2s/HWAIhE9Ew1W3ya4GisKX7UnGLrIGg/lYdmKB7iWmAYvvSIt2kiSVQzb7WTbyD8S4iYPltsgZPUE9bPw95jp1eILDNQMxysGppgvSAFkTqpiATsCO6+chPIq5h/Pzz/wFXBSgwcXkAAA=="; } + } + } +} diff --git a/Web/Migrations/201506181329243_VehicleInactiveDate.cs b/Web/Migrations/201506181329243_VehicleInactiveDate.cs new file mode 100644 index 0000000..4c97fd7 --- /dev/null +++ b/Web/Migrations/201506181329243_VehicleInactiveDate.cs @@ -0,0 +1,17 @@ +namespace MileageTraker.Web.Migrations +{ + using System.Data.Entity.Migrations; + + public partial class VehicleInactiveDate : DbMigration + { + public override void Up() + { + AddColumn("Vehicle", "InactiveDate", c => c.DateTime()); + } + + public override void Down() + { + DropColumn("Vehicle", "InactiveDate"); + } + } +} diff --git a/Web/Models/Vehicle.cs b/Web/Models/Vehicle.cs index ee92b6f..ff04946 100644 --- a/Web/Models/Vehicle.cs +++ b/Web/Models/Vehicle.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using MileageTraker.Web.Attributes; @@ -57,6 +58,11 @@ namespace MileageTraker.Web.Models [FormatHint("mm/yy")] public string PurDate { get; set; } + [DataType(DataType.DateTime)] + [DisplayFormat(NullDisplayText = "Currently Active", DataFormatString = @"{0:MM/dd/yyyy}")] + [FormatHint("mm/dd/yyyy")] + public DateTime? InactiveDate { get; set; } + [Required] [Display(Name = "Tag#")] [InputSize("small")] diff --git a/Web/Scripts/Shared/Site.js b/Web/Scripts/Shared/Site.js index d33c50d..0d8d1fd 100644 --- a/Web/Scripts/Shared/Site.js +++ b/Web/Scripts/Shared/Site.js @@ -120,7 +120,11 @@ function addButtonIcons () { 'Export': 'download', 'Import': 'upload', 'Driver Mileage': 'user', - 'Vehicle Mileage': 'car' + 'Vehicle Mileage': 'car', + 'Show Active': 'ok-circle', + 'Show Inactive': 'ban-circle', + 'Set Inactive' : 'ban-circle', + 'Reactivate' : 'ok-circle' }; $.each(textToIcon, function(text, icon) { $("a:contains('" + text + "'):not(:has(i))") diff --git a/Web/ViewModels/Vehicle/VehicleResultsViewModel.cs b/Web/ViewModels/Vehicle/VehicleResultsViewModel.cs new file mode 100644 index 0000000..9c355fb --- /dev/null +++ b/Web/ViewModels/Vehicle/VehicleResultsViewModel.cs @@ -0,0 +1,16 @@ +using System.Collections.Generic; + +namespace MileageTraker.Web.ViewModels.Vehicle +{ + public class VehicleResultsViewModel + { + public IEnumerable Vehicles { get; set; } + public bool Inactive { get; set; } + + public VehicleResultsViewModel(IEnumerable vehicles, bool activeInactive) + { + Vehicles = vehicles; + Inactive = activeInactive; + } + } +} \ No newline at end of file diff --git a/Web/Views/Shared/DisplayTemplates/DateTime.cshtml b/Web/Views/Shared/DisplayTemplates/DateTime.cshtml index 1cc93a6..30875ff 100644 --- a/Web/Views/Shared/DisplayTemplates/DateTime.cshtml +++ b/Web/Views/Shared/DisplayTemplates/DateTime.cshtml @@ -1,10 +1,21 @@ @using System.Globalization -@model DateTime +@model DateTime? @{ Layout = "~/Views/Shared/DisplayTemplates/_FieldLayout.cshtml"; var val = - ViewData.ModelMetadata.DisplayFormatString != null - ?string.Format(ViewData.ModelMetadata.DisplayFormatString, Model) - : Model.ToString(CultureInfo.InvariantCulture); + Model.HasValue + ? + ViewData.ModelMetadata.DisplayFormatString != null + ? string.Format(ViewData.ModelMetadata.DisplayFormatString, Model) + : Model.Value.ToString(CultureInfo.InvariantCulture) + : string.Empty; } -@Html.Encode(val) \ No newline at end of file +@if (Model == null) +{ + @Html.Encode(@ViewData.ModelMetadata.NullDisplayText) +} +else +{ + @Html.Encode(val) +} + diff --git a/Web/Views/Shared/DisplayTemplates/Object.cshtml b/Web/Views/Shared/DisplayTemplates/Object.cshtml index b8d84ef..cbb7912 100644 --- a/Web/Views/Shared/DisplayTemplates/Object.cshtml +++ b/Web/Views/Shared/DisplayTemplates/Object.cshtml @@ -2,7 +2,11 @@ @{ Layout = null; } -@foreach (var prop in ViewData.ModelMetadata.Properties.Where(pm => pm.ShowForDisplay && !pm.HideSurroundingHtml && !pm.ModelType.IsCollection())) +@foreach (var prop in ViewData.ModelMetadata.Properties.Where( + pm => pm.ShowForDisplay + && !pm.HideSurroundingHtml + && !pm.ModelType.IsCollection() + )) { @Html.Display(prop.PropertyName) } \ No newline at end of file diff --git a/Web/Views/Shared/EditorTemplates/DateTime.cshtml b/Web/Views/Shared/EditorTemplates/DateTime.cshtml index 523a06a..5d0ce76 100644 --- a/Web/Views/Shared/EditorTemplates/DateTime.cshtml +++ b/Web/Views/Shared/EditorTemplates/DateTime.cshtml @@ -1,13 +1,17 @@ -@model DateTime +@model DateTime? @{ Layout = "~/Views/Shared/EditorTemplates/_FieldLayout.cshtml"; var inputSize = (string)ViewData.ModelMetadata.AdditionalValues["InputSize"]; + var val = + Model.HasValue + ? Model.Value.ToShortDateString() + : string.Empty; } @if (!string.IsNullOrEmpty(inputSize)) { - @Html.TextBox("", (Model != DateTime.MinValue ? Model.ToShortDateString() : string.Empty ), new { @class = inputSize}) + @Html.TextBox("", (Model != DateTime.MinValue ? val : string.Empty ), new { @class = inputSize}) } else { - @Html.TextBox("", (Model != DateTime.MinValue ? Model.ToShortDateString() : string.Empty )) + @Html.TextBox("", (Model != DateTime.MinValue ? val : string.Empty )) } diff --git a/Web/Views/Vehicle/Details.cshtml b/Web/Views/Vehicle/Details.cshtml index 5d7cdcb..c120c3d 100644 --- a/Web/Views/Vehicle/Details.cshtml +++ b/Web/Views/Vehicle/Details.cshtml @@ -1,7 +1,7 @@ @model MileageTraker.Web.Models.Vehicle @{ - ViewBag.Title = "Vehicle Details"; + ViewBag.Title = "Vehicle Details " + (!Model.InactiveDate.HasValue ? "(Active)" : "(Inactive)"); } @section Styles { @@ -20,5 +20,13 @@
@Html.ActionLink("Edit", "Edit", new { id = Model.VehicleId }, new { @class = "btn" }) + @if (!Model.InactiveDate.HasValue) + { + @Html.ActionLink("Set Inactive", "SetInactive", new {id = Model.VehicleId}, new {@class = "btn"}) + } + else + { + @Html.ActionLink("Reactivate", "SetActive", new {id = Model.VehicleId}, new {@class = "btn"}) + } @Html.ActionLink("Logs", "Index", "Log", new { Model.VehicleId}, new { @class = "btn" })
\ No newline at end of file diff --git a/Web/Views/Vehicle/Index.cshtml b/Web/Views/Vehicle/Index.cshtml index 6fe8807..3bbf538 100644 --- a/Web/Views/Vehicle/Index.cshtml +++ b/Web/Views/Vehicle/Index.cshtml @@ -1,7 +1,7 @@ -@model IEnumerable +@model MileageTraker.Web.ViewModels.Vehicle.VehicleResultsViewModel @{ - ViewBag.Title = "Vehicles"; + ViewBag.Title = "Vehicles " + (!Model.Inactive ? "(Active)" : "(Inactive)"); } @section Styles { @@ -14,7 +14,8 @@
@Html.ActionLink("Add Another Vehicle", "Create", null, new{@class="btn"}) - @Html.ActionLink("Export", "Export", null, new { @class = "btn" }) + @Html.ActionLink("Export All", "Export", null, new { @class = "btn" }) + @Html.ActionLink(Model.Inactive ? "Show Active" : "Show Inactive", "Index", new {inactive = !Model.Inactive}, new { @class = "btn" })
@@ -51,7 +52,7 @@ -@foreach (var item in Model) { +@foreach (var item in Model.Vehicles) {
@Html.DisplayTextFor(m => item.Key) diff --git a/Web/Web.csproj b/Web/Web.csproj index 0cb4d87..2f78ce7 100644 --- a/Web/Web.csproj +++ b/Web/Web.csproj @@ -188,6 +188,10 @@ 201405210016138_CityFieldsRequired.cs + + + 201506181329243_VehicleInactiveDate.cs + @@ -210,6 +214,7 @@ +