diff --git a/Web/Controllers/FuelLogController.cs b/Web/Controllers/FuelLogController.cs index b1f5bfa..a803836 100644 --- a/Web/Controllers/FuelLogController.cs +++ b/Web/Controllers/FuelLogController.cs @@ -6,6 +6,8 @@ using MileageTraker.Web.Attributes; using MileageTraker.Web.DAL; using MileageTraker.Web.Utility; using MileageTraker.Web.ViewModels.FuelLog; +using MileageTraker.Web.ViewModels.Log; +using ImportUploadViewModel = MileageTraker.Web.ViewModels.FuelLog.ImportUploadViewModel; namespace MileageTraker.Web.Controllers { @@ -46,6 +48,13 @@ namespace MileageTraker.Web.Controllers return View(viewModel); } + public ViewResult Details(int id) + { + var fuelLog = DataService.GetFuelLog(id); + var vm = new FuelLogViewModel(fuelLog); + return View(vm); + } + #region Import public ActionResult ImportUpload() diff --git a/Web/Controllers/LogController.cs b/Web/Controllers/LogController.cs index 0608de6..64c459b 100644 --- a/Web/Controllers/LogController.cs +++ b/Web/Controllers/LogController.cs @@ -226,12 +226,12 @@ namespace MileageTraker.Web.Controllers return RedirectToAction("Index"); } - public PartialViewResult DetailsPartial(int id) + public PartialViewResult DetailsPrevious(int id) { var log = DataService.GetLog(id); return PartialView(new LogPartialDetails(log)); } - + #region Import public ActionResult ImportUpload() diff --git a/Web/DAL/DataService.cs b/Web/DAL/DataService.cs index b5252ab..a1846e6 100644 --- a/Web/DAL/DataService.cs +++ b/Web/DAL/DataService.cs @@ -614,7 +614,7 @@ namespace MileageTraker.Web.DAL #endregion -#region FuelLog + #region FuelLog public void AddFuelLog(FuelLog fuelLog) { diff --git a/Web/ViewModels/FuelLog/FuelLogViewModel.cs b/Web/ViewModels/FuelLog/FuelLogViewModel.cs new file mode 100644 index 0000000..a29adfa --- /dev/null +++ b/Web/ViewModels/FuelLog/FuelLogViewModel.cs @@ -0,0 +1,68 @@ +using System; +using System.ComponentModel.DataAnnotations; +using System.Web.Mvc; +using AutoMapper; + +namespace MileageTraker.Web.ViewModels.FuelLog +{ + public class FuelLogViewModel + { + [HiddenInput(DisplayValue = false)] + public int FuelLogId { get; set; } + + [Required] + [DataType(DataType.Date)] + [DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:d}")] + public DateTime Date { get; set; } + + [Required] + [StringLength(128)] + [Display(Name = "Driver Name")] + public string DriverFullName { get; set; } + + [Required] + [Display(Name = "Tag#")] + public string TagNumber { get; set; } + + [Required] + public int Odometer { get; set; } + + [StringLength(64)] + [Display(Name = "City Name")] + public string CityName { get; set; } + + [Display(Name = "MPG")] + public double MPG { get; set; } + + [Required] + [Display(Name = "Gas Purchased")] + public double GasPurchased { get; set; } + + [Required] + [Display(Name = "Total Price")] + public decimal TotalPrice { get; set; } + + // Matched log + [HiddenInput(DisplayValue = false)] + public int? LogId { get; set; } + + static FuelLogViewModel() + { + Mapper.CreateMap(); + Mapper.CreateMap() + .ForMember(dest => dest.LogId, + opt => opt.ResolveUsing( + fl => fl.Log != null ? (int?)fl.Log.LogId : null + )); + } + + public FuelLogViewModel(Models.FuelLog fuelLog) + { + Mapper.Map(fuelLog, this); + } + + public FuelLogViewModel() + { + } + } +} \ No newline at end of file diff --git a/Web/Views/FuelLog/Details.cshtml b/Web/Views/FuelLog/Details.cshtml new file mode 100644 index 0000000..feee5ba --- /dev/null +++ b/Web/Views/FuelLog/Details.cshtml @@ -0,0 +1,20 @@ +@model MileageTraker.Web.ViewModels.FuelLog.FuelLogViewModel + +@{ + ViewBag.Title = "Fuel Log Details"; +} + +@Html.Partial("_StatusMessage") + +

@ViewBag.Title

+ +
+ @Html.DisplayForModel() +
+ +
+ @if (Model.LogId != null) + { + @Html.ActionLink("View Mileage Log", "Details", "Log", new {id = Model.LogId}, new {@class = "btn"}) + } +
\ No newline at end of file diff --git a/Web/Views/Log/DetailsPartial.cshtml b/Web/Views/Log/DetailsPrevious.cshtml similarity index 100% rename from Web/Views/Log/DetailsPartial.cshtml rename to Web/Views/Log/DetailsPrevious.cshtml diff --git a/Web/Views/Log/Index.cshtml b/Web/Views/Log/Index.cshtml index be45f57..6bc8209 100644 --- a/Web/Views/Log/Index.cshtml +++ b/Web/Views/Log/Index.cshtml @@ -63,7 +63,7 @@ if (item.PreviousLogId != null) { string miles = (item.Miles).ToString(); - return Html.ActionLink(miles, "DetailsPartial", new { id = item.PreviousLogId }, new { @class = "qtip-modal" }); + return Html.ActionLink(miles, "DetailsPrevious", new { id = item.PreviousLogId }, new { @class = "qtip-modal" }); } return Html.Raw("?"); }), diff --git a/Web/Web.csproj b/Web/Web.csproj index 21a28e0..de2ae2f 100644 --- a/Web/Web.csproj +++ b/Web/Web.csproj @@ -230,6 +230,7 @@ + @@ -305,6 +306,8 @@ + + @@ -508,9 +511,6 @@ - - -