Add currency attribute

This commit is contained in:
2015-10-08 14:17:30 -04:00
parent 13fc366dc5
commit 6482955b3c
7 changed files with 79 additions and 4 deletions
+33 -1
View File
@@ -11,7 +11,7 @@ namespace MileageTraker.Web.Controllers
{
public ActionResult Index(VehicleServiceQueryViewModel query)
{
var vehicleServices = DataService.GetVehicleServices();
var vehicleServices = DataService.GetVehicleServices().ToList();
var viewModel = new VehicleServiceResultsViewModel
{
ServiceItems = vehicleServices.Select(s => new VehicleServiceViewModel(s))
@@ -19,6 +19,13 @@ namespace MileageTraker.Web.Controllers
return View(viewModel);
}
public ViewResult Details(int id)
{
var vehicleService = DataService.GetVehicleService(id);
var viewModel = new VehicleServiceViewModel(vehicleService);
return View(viewModel);
}
public ActionResult Create()
{
return View();
@@ -32,6 +39,7 @@ namespace MileageTraker.Web.Controllers
{
var vehicleService = viewModel.GetVehicleService();
vehicleService.Vehicle = DataService.GetVehicle(viewModel.VehicleId);
DataService.AddVehicleService(vehicleService);
@@ -43,5 +51,29 @@ namespace MileageTraker.Web.Controllers
return View(viewModel);
}
public ActionResult Edit(int id)
{
var vehicleService = DataService.GetVehicleService(id);
var viewModel = new VehicleServiceViewModel(vehicleService);
return View(viewModel);
}
[HttpPost]
[ActionLog]
public ActionResult Edit(VehicleServiceViewModel viewModel)
{
if (ModelState.IsValid)
{
var vehicleService = viewModel.GetVehicleService();
vehicleService.Vehicle = DataService.GetVehicle(viewModel.VehicleId);
DataService.UpdateVehicleService(vehicleService);
TempData["StatusMessage"] = "Changes saved for vehicle service " + vehicleService.Vehicle.VehicleId;
return RedirectToAction("Details", new { id = vehicleService.VehicleServiceId });
}
return View(viewModel);
}
}
}
+1 -1
View File
@@ -823,7 +823,7 @@ namespace MileageTraker.Web.DAL
return vehicleServices;
}
public VehicleService GetVehicleServices(string id)
public VehicleService GetVehicleService(int id)
{
return _db.VehicleServices.Find(id);
}
@@ -2,6 +2,7 @@
using System.ComponentModel.DataAnnotations;
using System.Web.Mvc;
using AutoMapper;
using MileageTraker.Web.Attributes;
using MileageTraker.Web.ViewModels.Log;
namespace MileageTraker.Web.ViewModels.FuelLog
@@ -44,6 +45,7 @@ namespace MileageTraker.Web.ViewModels.FuelLog
[Required]
[Display(Name = "Total Price")]
[Currency]
public decimal TotalPrice { get; set; }
// Matched log
@@ -36,7 +36,7 @@ namespace MileageTraker.Web.ViewModels.VehicleService
[Required]
[InputSize("small")]
[Units("$")]
[Currency]
public decimal Price { get; set; }
[StringLength(64, MinimumLength = 3, ErrorMessage = "Minimum 3 characters")]
@@ -45,7 +45,8 @@ namespace MileageTraker.Web.ViewModels.VehicleService
static VehicleServiceViewModel()
{
Mapper.CreateMap<VehicleServiceViewModel, Models.VehicleService>();
Mapper.CreateMap<Models.VehicleService, VehicleServiceViewModel>();
Mapper.CreateMap<Models.VehicleService, VehicleServiceViewModel>()
.ForMember(dest => dest.VehicleId, opt => opt.MapFrom(src => src.Vehicle.VehicleId));
}
public VehicleServiceViewModel(Models.VehicleService vehicleService)
+16
View File
@@ -0,0 +1,16 @@
@model MileageTraker.Web.ViewModels.VehicleService.VehicleServiceViewModel
@{
ViewBag.Title = "Vehicle Service Details" ;
}
@Html.Partial("_StatusMessage")
<h2 class="center-content"><i class="fa fa-wrench"></i> @ViewBag.Title</h2>
<div class="center-content well">
@Html.DisplayForModel()
</div>
<div class="center-content btn-toolbar">
@Html.ActionLink("Edit", "Edit", new { id = Model.VehicleServiceId }, new { @class = "btn" })
</div>
+21
View File
@@ -0,0 +1,21 @@
@model MileageTraker.Web.ViewModels.VehicleService.VehicleServiceViewModel
@{
ViewBag.Title = "Edit Vehicle Service";
}
@Html.Partial("_StatusMessage")
<h2 class="center-content"><i class="fa fa-wrench"></i> @ViewBag.Title</h2>
@using (Html.BeginForm("Edit", "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="Save" class="btn btn-primary" />
</div>
</fieldset>
}
+3
View File
@@ -130,6 +130,7 @@
</ItemGroup>
<ItemGroup>
<Compile Include="Attributes\ActionLogAttribute.cs" />
<Compile Include="Attributes\CurrencyAttribute.cs" />
<Compile Include="Attributes\DenyFutureDateAttribute.cs" />
<Compile Include="Attributes\DenyPreviousMonthDateAttribute.cs" />
<Compile Include="Attributes\FormatHintAttribute.cs" />
@@ -330,6 +331,8 @@
<Content Include="Views\Shared\EditorTemplates\FuelLogResultsViewModel.cshtml" />
<Content Include="Views\VehicleService\Index.cshtml" />
<Content Include="Views\VehicleService\Create.cshtml" />
<Content Include="Views\VehicleService\Edit.cshtml" />
<Content Include="Views\VehicleService\Details.cshtml" />
</ItemGroup>
<ItemGroup>
<Content Include="Content\Account.Login.css" />